找点自信吧

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution {
public boolean isHappy(int n) {
Set<Integer> hs = new HashSet<>();
int res = 0;
while(true){
while(n > 0){
res = res + ((n%10)*(n%10));
n /= 10;
}
if(hs.contains(res)) return false;
if(res == 1) return true;
hs.add(res);
n = res;
res = 0;
}
}
}