lintcode: Check Sum of Square Numbers
Check Sum of Square Numbers
Given a integer c
, your task is to decide whether there're two integers a and b such that a^2 + b^2 = c
.
Given n = 5
Return true
// 1 * 1 + 2 * 2 = 5
Given n = -5
Return false
代码
class Solution {
public:
/*
* @param : the given number
* @return: whether whether there're two integers
*/
bool checkSumOfSquareNumbers(int num) {
// write your code here
if (num < ) {
return false;
}
int c = floor(sqrt(num));
int i = c;
if (i * i == num) return true;
int j = ;
while (j <= i) {
if (i * i + j * j == num) {
return true;
} else if (i * i + j * j < num) {
j++;
} else {
i--;
}
}
return false;
}
};
lintcode: Check Sum of Square Numbers的更多相关文章
- 【Leetcode_easy】633. Sum of Square Numbers
problem 633. Sum of Square Numbers 题意: solution1: 可以从c的平方根,注意即使c不是平方数,也会返回一个整型数.然后我们判断如果 i*i 等于c,说明c ...
- [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 ...
- 633. Sum of Square Numbers【Easy】【双指针-是否存在两个数的平方和等于给定目标值】
Given a non-negative integer c, your task is to decide whether there're two integers a and bsuch tha ...
- [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 ...
- 【LeetCode】633. Sum of Square Numbers
Difficulty: Easy More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/sum-of-square-n ...
- LeetCode633. Sum of Square Numbers(双指针)
题意:给定一个非负整数c,确定是否存在a和b使得a*a+b*b=c. class Solution { typedef long long LL; public: bool judgeSquareSu ...
- C#LeetCode刷题之#633-平方数之和( Sum of Square Numbers)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3885 访问. 给定一个非负整数 c ,你要判断是否存在两个整数 ...
- [Swift]LeetCode633. 平方数之和 | 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 ...
- LeetCode算法题-Sum of Square Numbers(Java实现)
这是悦乐书的第276次更新,第292篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第144题(顺位题号是633).给定一个非负整数c,判断是否存在两个整数a和b,使得a的 ...
随机推荐
- 【luogu P3393 逃离僵尸岛】 题解
题目链接:https://www.luogu.org/problemnew/show/P3393 被占领的点可以先连在一个点上然后只需要对这一个点bfs一遍就可以求所有的危险点 #include &l ...
- 阿里云云服务器Windows Server 2012 R2无法安装IIS等组件的解决办法
Windows Server2012 R2数据中心版 不管安装什么组件,都显示存储空间不足,无法应用命令,错误代码0x80070008. 最终确认是服务器配置过低的原因,因为这个型号是低级别的配置,1 ...
- IOS本地日志记录解决方案
我们在项目中日志记录这块也算是比较重要的,有时候用户程序出什么问题,光靠服务器的日志还不能准确的找到问题 现在一般记录日志有几种方式: 1.使用第三方工具来记录日志,如腾讯的Bugly,它是只把程序的 ...
- 2018 CVTE 前端校招笔试题整理
昨天晚上(7.20)做了CVTE的前端笔试,总共三十道题,28道多选题,2道编程题 .做完了之后觉得自己基础还是不够扎实,故在此整理出答案,让自己能从中得到收获,同时给日后的同学一些参考. 首先说一下 ...
- 开源框架:DBUtils使用详解
一.先熟悉DBUtils的API: 简介:DbUtils是一个为简化JDBC操作的小类库. (一)整个dbutils总共才3个包: 1.包org.apache.commons.dbutils 接 ...
- 生产环境MySQL数据库集群MHA上线实施方案
生产环境MySQL数据库集群MHA上线实施方案 一.不停库操作 1.在所有节点安装MHAnode所需的perl模块(需要有安装epel源) yum install perl-DBD-MySQL -y ...
- 大数据学习--day10(继承-权限-super-final-多态-组合)
继承-权限-super-final-多态-组合 权限修饰符 内容 public protected default(不写就是它) ...
- Python2和Python3
1. 字符编码 1.1. Python2默认为ACSII编码 1.2. Python3为Unicode 2. Unicode和UTF8和GBK编码的关系 utf8:中文3字节 ...
- ubuntu 防止软件包自动更新
阻止软件包升级 有两种方法阻止软件包升级,使用dpkg,或者在Woody中使用APT. 使用dpkg,首先导出软件包选择列表: dpkg --get-selections \* > select ...
- 小程序开发-13-小程序wxs的应用
内容简介的换行 问题:因为微信的<text></text>标签能够转义\n,所以从服务器加载来的数据我们可以直接放到这个标签中,\n就会自己换行了.问题是服务器返回来的数据多了 ...