Fork me on github

【每日一题】633. 平方数之和

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

思路:二分法

class Solution {
    public boolean judgeSquareSum(int c) {
        int left = 0, right = (int)Math.sqrt(c);
        while(left <= right){
            int sum = left * left + right * right;
            if(sum == c){
                return true;
            }
            if(sum > c){
                right --;
            }
            else{
                left++;
            }
        }
        return false;
    }
}
posted @ 2021-04-28 09:25  zjy4fun  阅读(46)  评论(0编辑  收藏  举报