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题解之判断是否为平方数之和的更多相关文章
- C#版 - Leetcode 633. 平方数之和 - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - L ...
- [LeetCode] Sum of Square Numbers 平方数之和
Given a non-negative integer c, your task is to decide whether there're two integers a and b such th ...
- C#刷遍Leetcode面试题系列连载(4) No.633 - 平方数之和
上篇文章中一道数学问题 - 自除数,今天我们接着分析 LeetCode 中的另一道数学题吧~ 今天要给大家分析的面试题是 LeetCode 上第 633 号问题, Leetcode 633 - 平方数 ...
- [LeetCode] 633. Sum of Square Numbers 平方数之和
Given a non-negative integer c, your task is to decide whether there're two integers a and b such th ...
- Java实现 LeetCode 633 平方数之和(暴力大法)
633. 平方数之和 给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a2 + b2 = c. 示例1: 输入: 5 输出: True 解释: 1 * 1 + 2 * 2 = 5 ...
- 【JavaScript】Leetcode每日一题-平方数之和
[JavaScript]Leetcode每日一题-平方数之和 [题目描述] 给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a2 + b2 = c . 示例1: 输入:c = 5 ...
- leetcode.双指针.633平方数之和-Java
1. 具体题目 给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a^2 + b^2 = c. 示例1: 输入: 5 输出: True 解释: 1 * 1 + 2 * 2 = 5 注 ...
- 力扣(LeetCode)平方数之和 个人题解
给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a2 + b2 = c. 示例1: 输入: 5 输出: True 解释: 1 * 1 + 2 * 2 = 5 示例2: 输入: 3 ...
- LeetCode 633. Sum of Square Numbers平方数之和 (C++)
题目: Given a non-negative integer c, your task is to decide whether there're two integers a and b suc ...
随机推荐
- VS2013 堆栈溢出调查(0xC00000FD: Stack overflow)
在调试一个代码时,执行过程中会出现如下错误(0xC00000FD: Stack overflow). 很明显是堆栈溢出了. 网上很多方法,都是通过修改设置工程配置,把堆栈调大一些,如下图. 但是堆栈到 ...
- Hive:把一段包含中文的sql脚本粘贴到beeline client运行中文乱码
背景: 在做项目过程中不可能hive表中都是非中文字段.在最近做的项目中就遇到需要在beeline界面上执行查询脚本,但脚本中包含中文,正常一个脚本用文本写好后,粘贴到beeline窗口运行时,发现中 ...
- [转]XHR简介
在XHR诞生前,网页要获取客户端和服务器的任何状态更新,都需要刷新一次,在XHR诞生后就可以完全通过JS代码异步实现这一过程.XHR的诞生也使最初的网页制作转换为开发交互应用,拉开了WEB2.0的 ...
- U盘分区后合并
1.首先把你的U盘插在电脑上,点击开始→所有程序→附件→命令提示符(前面这步骤也可以直接用Win+R组合键打开"运行",之后输入cmd也可打开命令提示符). 2.然后在命令提示窗口 ...
- 关于Go 的 Interface
最近在用Go语言写程序, 其中遇到一个场景:写了一个接口,3个实现接口的struct. 另外一个struct包含此接口,根据构造函数赋予不同的结构实现. 一开始struct里写的是接口的地址,但是在创 ...
- [Ubuntu 16.04 LTS ]屏幕分辨率 Unknown display
新装完Ubuntu 16.04 LTS 通过System settings-->Displays 设置屏幕分辨率 显示"Unknown display",选择后无反应,并且屏 ...
- [Luogu 3807]【模板】卢卡斯定理
Description 给定n,m,p(1≤n,m,p≤10^5) 求 C_{n+m}^{m} \mod p 保证P为prime C表示组合数. 一个测试点内包含多组数据. Input 第一行一 ...
- Educational Codeforces Round 18
A. New Bus Route 题目大意:给出n个不同的数,问差值最小的数有几对.(n<=200,000) 思路:排序一下,差值最小的一定是相邻的,直接统计即可. #include<cs ...
- HDU2425:Hiking Trip(BFS+优先队列)
给出一个地图,地图有四种路面,经过每种路面花费的时间不同,问从起点到终点所花费的最少时间是多少 把到各个点的花费存入队列中,然后弹出,即可得到最小 Sample Input 4 6 1 2 10 T. ...
- QSDK下驱动AR8035
0 概述 QSDK平台中,我所接触到的版本,能支持MIPS架构的,是基于Openwrt AA版本:虽然CC版本上就已经能很好地支持AR8035了,可是AA版本它本身是不支持的,于是不断有人要求提供补丁 ...