3 ms solution


  • 0
    A
      bool judgeSquareSum(int c) {
            if(c==0 || c==1 || c==2)
                return true;
            long int a=0;
            long int b=1;
            while(b!=c && a!=c && a<=b)
            {   
            if(a*a+b*b == c)
                return true;
            
            if(a*a+b*b > c)
            {
                b--;
                a++;
            }
            else
            {
                b++;
            }
        }
            return false;
        }
    
    

Log in to reply
 

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