```
public boolean isHappy(int n) {
HashSet<Integer> set = new HashSet();
set.add(n);
return helper(n, set);
}
public boolean helper(int n, HashSet<Integer> set){
if(n == 1)
return true;
int num = 0;
while(n > 0){
num += Math.pow(n % 10, 2);
n /= 10;
}
if(set.add(num))
return helper(num, set);
return false;
}
```