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/


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM