https://leetcode-cn.com/problems/sum-of-square-numbers/submissions/
注意是a<=b,不然当c=2时发生错误,
解法同167
代码:
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; } }