class Solution

{

public:

bool isHappy(int n) {

int temp = 0;

unordered_set<int> myset;

//int sum = 0; //If I definite sum here, the code will not pass, why?

if(n == 1){

return true;

}

while (1)

{

int sum = 0;

while(n != 0){

temp = n % 10;

n = n / 10;

sum = sum + temp * temp;

}

if(sum == 1){

return true;

}

else{

if(myset.find(sum) == myset.end()){

myset.insert(sum);

}

else{

return false;

}

}

n = sum;

```
}
return true;
```

}

};