```
class Solution {
public:
bool isHappy(int n) {
if(n == 1)
return true;
int result = 0;
while(1)
{
while(n < 10)
n = n * n;
while(n > 0)
{
result += (n%10) * (n%10);
n = (n - n%10) / 10;
}
if(result == 1)
return true;
else if(result < 10)
return false;
else
{
n = result;
result = 0;
}
}
}
};
```