(int n)
| 1 | class Solution { |
| 2 | |
| 3 | public boolean isHappy(int n) { |
| 4 | if (n == 1 || n == -1) { |
| 5 | return true; |
| 6 | } |
| 7 | |
| 8 | Set<Integer> visit = new HashSet<Integer>(); |
| 9 | |
| 10 | // compute square until getting duplicate value |
| 11 | while (!visit.contains(n)) { |
| 12 | visit.add(n); |
| 13 | // using helper function to compute the sum of squares |
| 14 | n = sumOfSquare(n); |
| 15 | |
| 16 | if (n == 1) return true; |
| 17 | } |
| 18 | |
| 19 | return false; |
| 20 | } |
| 21 | |
| 22 | public int sumOfSquare(int n) { |
| 23 | int output = 0; |
nothing calls this directly
no test coverage detected