C++ very simple O(1) space solution


  • 5
    M
    bool judgeSquareSum(int c) {
            for(int i=0;i<=sqrt(c);i++) {
                int t=sqrt(c-i*i);
                if(t*t==c-i*i) return true;
            }
            return false;
        }

Log in to reply
 

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