202. 快乐数
小于 1 分钟
202. 快乐数简单
class Solution {
public boolean isHappy(int n) {
HashSet<Integer> set = new HashSet<>();
while (true) {
if (!set.contains(n)) {
set.add(n);
int count = 0;
while(n != 0) {
count += Math.pow(n % 10, 2);
n /= 10;
}
if (count == 1)
return true;
else
n = count;
} else {
return false;
}
}
}
}
Powered by Waline v2.15.5