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的 ...
随机推荐
- js内部事件机制--单线程原理
原文地址:https://www.xingkongbj.com/blog/js/event-loop.html http://www.haorooms.com/post/js_xiancheng ht ...
- #leetcode刷题之路37-解数独
编写一个程序,通过已填充的空格来解决数独问题.一个数独的解法需遵循如下规则:数字 1-9 在每一行只能出现一次.数字 1-9 在每一列只能出现一次.数字 1-9 在每一个以粗实线分隔的 3x3 宫内只 ...
- Docker镜像浅谈
先抛出几个我在学习过程中产生的几个问题. 1. 容器镜像是什么, 和装系统时的镜像有什么关系? 2. 容器镜像的作用是什么? 3. 不同版本的ubuntu镜像有什么区别, 比如说 ubuntu:18. ...
- 第四模块MySQL50题作业,以及由作业引申出来的一些高端玩法
一.表关系 先参照如下表结构创建7张表格,并创建相关约束 班级表:class 学生表:student cid caption grade_id ...
- 第3章 jQuery中的DOM操作
parent() .parents().closest() 区别示例: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitiona ...
- 理解Redux以及如何在项目中的使用
今天我们来聊聊Redux,这篇文章是一个进阶的文章,建议大家先对redux的基础有一定的了解,在这里给大家推荐一下阮一峰老师的文章: http://www.ruanyifeng.com/blog/20 ...
- redis集群部署步骤
1.yum 安装依赖 yum install gcc unzip wget 2.编译安装redis,编译安装的目的是源码包内包含了接下来创建redis集群所需要的 redis-trib.rb脚本 ma ...
- php源码建博客3--区分平台的MVC结构
主要: 模型单例工厂 目录结构优化 区分平台(前台,后台....) --------------文件结构:-------------------------------------- blog├─Ap ...
- Qt上FFTW組件的编译与安裝
Qt上FFTW組件的編譯安裝 FFTW是一個做頻譜非常實用的組件,本文講述在Windows和Linux兩個平臺使用FFTW組件.Windows下的的FFTW組件已經編譯好成爲dll文件,按照開發應用的 ...
- python学习——单例模式
在python中,单例模式在面试中非常重要.下面来给大家推荐一个Python中实现单例模式的博客地址. https://www.cnblogs.com/huchong/p/8244279.html