class Solution {
public:
//相当于指针往后面移动一步
int BitSum(int num)
{
int ret = 0;
while(num)
{
ret += pow(num % 10, 2);
num /= 10;
}
return ret;
}
bool isHappy(int n) {
int slow = n;
int fast = BitSum(n);
while(fast != slow)
{
slow = BitSum(slow);
fast = BitSum(BitSum(fast));
}
//走到这里,说明一定是相遇了,判断就是了
if(fast == 1)return true;
return false;
}
};