Easy & Fast C++ Solution. But, What is the time Complexity?


  • 0
    C
    class Solution {
    public:
        bool isSq(int v){
            return (int)sqrt(v) * (int)sqrt(v) == v;
        }
        bool judgeSquareSum(int c) {
            
            for(int i=0;i<=sqrt(c);i++){//i从0开始 毕竟c可以为0
                if(isSq(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.