码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-11-26 11:10:13      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:来源   highlight   public   blank   ref   题目   param   turn   分享   

技术分享图片

 

 

简单粗暴

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/

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

标签:来源   highlight   public   blank   ref   题目   param   turn   分享   

原文地址:http://www.cnblogs.com/cc11001100/p/7898182.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!