```
bool isHappy(int n) {
int n_copy = n;
while (n_copy >= 10 ) {
n_copy = IsHappySingleStep(n_copy);
}
return n_copy == 1 || n_copy == 7;
}
int IsHappySingleStep(int n) {
int result = 0;
int lastNum = n % 10;
while (n != 0){
result += lastNum * lastNum;
n /= 10;
lastNum = n % 10;
}
return result;
}
```