633. 平方数之和

题目链接:https://leetcode-cn.com/problems/sum-of-square-numbers/submissions/

代码:

class Solution {
    public boolean judgeSquareSum(int c) {
        long a=0;
        long b=(long) (Math.sqrt(c) + 1);
        while(a <= b) {
            if(a*a + b*b == c) {
//                System.out.println(a);
//                System.out.println(b);
                return true;
            }else if(a*a + b*b > c) {
                b--;
            }else if(a*a + b*b < c) {
                a++;
            }
        }
//        System.out.println(a);
//        System.out.println(b);
//        System.out.println(a*a + b*b);
        return false;
    }
}

思路:直接暴力

原文地址:https://www.cnblogs.com/rao11/p/11839952.html