```
public class Solution {
HashSet<Integer> hs = new HashSet<Integer>();
public boolean isHappy(int n) {
if (n == 1){
return true;
}
else {
int sum = 0;
while (n > 0){
int x = n % 10;
sum += x * x;
n /= 10;
}
if (!hs.contains(sum)){
hs.add (sum);
return isHappy (sum);
}
else {
return false;
}
}
}
}
```