题目
代码实现:
class Solution {
public boolean isHappy(int n) {
HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
while(!map.containsKey(n) && n != 1){
map.put(n,1);
n = Happy(n);
}
return n == 1;
}
public int Happy(int n){
int result = 0,cur = 0;
while(n>0){
cur = n%10;
result += cur*cur;
n = n/10;
}
return result;
}
}
结果: