Fork me on GitHub

LintCode题解之判断是否为平方数之和

 

 

简单粗暴

public class Solution {
    
    /*
     * @param : the given number
     * @return: whether whether there're two integers
     */
    public boolean checkSumOfSquareNumbers(int n) {
        int max = (int)Math.sqrt(n) + 1;
        for(int i=0; i<max; i++){
            for(int j=0; j<max; j++){
                if(i*i + j*j == n) return true;
            }
        }
        return false;
    }
    
};

 

题目来源: http://www.lintcode.com/zh-cn/problem/check-sum-of-square-numbers/

posted @ 2017-11-26 03:55  CC11001100  阅读(899)  评论(5编辑  收藏  举报