题目:
题解:
//计算的过程函数,我没重点讲,很简单看一下代码就好了
int getSum(int n) {
int sum = 0;
while (n) {
sum += (n % 10) * (n % 10);
n /= 10;
}
return sum;
}
bool isHappy(int n){
int sum = getSum(n);
int hash[820] = {0};
while (sum != 1) {
if (hash[sum] == 1) {
return false;
} else {
hash[sum]++;
}
sum = getSum(sum);
}
return true;
}