Really Stupid, but Works


  • 0
    M

    Generate all valid squares quickly, then O(1) lookup.

    Max ops is guaranteed to be magnitudes beyond 50K, so solution was guaranteed to work.

            HashSet<Integer> squares = new HashSet<Integer>();
            for(int i=1;i<50000;i++){
                int n = i*i;
                if(n > 0)
                    squares.add(n);
                else
                    break;
            }
            return squares.contains(num);```

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.