4-liner C++ with upper bound sqrt(c/2)


  • 0
        bool judgeSquareSum(int c) {
            for (int a = 0; a <= sqrt(c/2); ++a) {
                int b = sqrt(c - a*a);
                if (b*b + a*a == c) return true;
            }
            return false;
        }
    

Log in to reply
 

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