```
class Solution {
public:
bool isHappy(int n) {
int k, digit;
int i = 0;
while(n>1){
k = 0;
while(n){
digit = n%10;
k += digit*digit;
n/=10;
}
if(i++ > 8) break;
n=k;
}
return n == 1;
}
};
```