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