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

}