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.

您在真实的面试中是否遇到过这个题?

Yes
样例

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;
}
};

最新文章

  1. ruby -- 进阶学习(一)subdomain配置与实现
  2. 你的java 代码对JIT编译友好吗?
  3. Objective-C设计模式——原型Prototype(对象创建)
  4. 【UVA1379】Pitcher Rotation (贪心+DP)
  5. js中的潜伏者之Arguments对象
  6. nutch2.3中nutch-site.xml设置说明
  7. FileStream:The process cannot access the file because it is being used by another process
  8. UITextField 设置 placeholder 的字体颜色方法
  9. 集美大学网络1413第十五次作业成绩(团队十) -- 项目复审与事后分析(Beta版本)
  10. 偏置方差分解Bias-variance Decomposition
  11. UOJ#73. 【WC2015】未来程序 提交答案题
  12. 【XSY2727】Remove Dilworth定理 堆 树状数组 DP
  13. js操作数组元素
  14. Hdu2015 偶数求和
  15. 彻底删除windows残留启动引导
  16. _ai_creature
  17. mysql row日志格式下 查看binlog sql语句
  18. kafka 主要内容介绍
  19. 《剑指offer》第二十一题(调整数组顺序使奇数位于偶数前面)
  20. Mysql主从同步在线实施步骤【适合大数据库从库配置】

热门文章

  1. Python入门基础:代码的编码风格
  2. 如何解决使用JMeter时遇到的问题
  3. LeetCode21.合并两个有序链表 JavaScript
  4. Paths with -a does not make sense.
  5. #leetcode刷题之路13-罗马数字转整数
  6. hdu_4465_Candy
  7. nginx通过upstream实现负载均衡
  8. 【淘宝客】批量提取QQ号
  9. mysql的char,varchar,text,blob
  10. python中如何退出多层循环