6ms C++ solution


  • 0
    N
    bool judgeSquareSum(int c) {   
            for(int i=0;i<= (int)sqrt(c);++i)
                if(is_perfect_square(c-i*i)) // check if the number is a perfect square
                    return true;
            
            return false;
        }
        bool is_perfect_square(int num){
            int sq = sqrt(num);
            return sq*sq == num; //return true if perfect square
        }

Log in to reply
 

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