public boolean isHappy2(int n){
  if (n < 1)   return false;
  int num=n;
  Set<Integer> results=new HashSet<>();
  while (!results.contains(num)) {
    results.add(num);
    num=digitSquareSum(num);
  }
  return num == 1;
}

public boolean isHappy2 ( int n ) { if ( n < 1 ) return false ; int num = n ; Set < Integer > results = new HashSet < > ( ) ; while ( ! results . contains ( num ) ) { results . add ( num ) ; num = digitSquareSum ( num ) ; } return num == 1 ; }
loop detection using set , use more space
