IT常识
技术 Python PHP JavaScript IOS Android Java 数据库 资源 公众号 代码片段 github
  • IT常识
  • 技术

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

Posted 2020-10-15

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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/

以上是关于LintCode题解之判断是否为平方数之和的主要内容,如果未能解决你的问题,请参考以下文章

《LeetCode之每日一题》:29.平方数之和

力扣(LeetCode)平方数之和 个人题解

Leetcode633题平方数之和

633. 平方数之和

力扣小记

4.11 每日一题题解

(c)2006-2024 SYSTEM All Rights Reserved IT常识