Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Leetcode 202 Happy Number
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; //LEETCODE 202 Happy Number class Rextester { public static void main(String args[]) { System.out.println(isHappy(19)); } public static boolean isHappy(int n) { Set<Integer> set = new HashSet<>(); int sum = 0; while(sum!=1 && !set.contains(n)){ sum = 0; set.add(n); int tmp = n; while(tmp>0){ sum +=(tmp%10)*(tmp%10); tmp = tmp/10; } n = sum; } if(sum==1) return true; return false; } }
run
|
edit
|
history
|
help
0
1a
mostrar pam
1d
An excursion with Strings
1.6
3.B
Find a dot in a string
Basic_Structure
combination sum (variation)
pk2