class Solution {
public:
bool isHappy(int n) {
set<int> haha;
do{
int ans = 0;
if(haha.find(n) != haha.end()) return 0;
haha.insert(n);
while(n > 0){
ans += (n%10)*(n%10);
n/=10;
}
n = ans;
if(n == 1) return 1;
} while(1);
}
};