and the number of squares leetcode 633. (double pointer java)

https://leetcode-cn.com/problems/sum-of-square-numbers/submissions/

 

Note that is a <= b, = 2 when an error occurs when otherwise c,

Solution with 167

 

Code:

class Solution {
    public boolean judgeSquareSum(int c) {
        int a=0,b=(int)Math.sqrt(c);
        while(a<=b){
            int sum=a*a+b*b;
            if(sum==c)
                return true;
            if(sum>c)
                b--;
            else
                a++;
        }
        return false;
    }
}

 

Guess you like

Origin www.cnblogs.com/y1040511302/p/11431948.html