LeetCode633. Sum of Square Numbers(双指针)
题意:给定一个非负整数c,确定是否存在a和b使得a*a+b*b=c。
class Solution {
typedef long long LL;
public:
bool judgeSquareSum(int c) {
LL head = 0;
LL tail = (LL)(sqrt(c));
while(head <= tail){
LL sum = head * head + tail * tail;
if(sum == (LL)c) return true;
else if(sum > (LL)c) --tail;
else ++head;
}
return false;
}
};
LeetCode633. Sum of Square Numbers(双指针)的更多相关文章
- Leetcode633.Sum of Square Numbers平方数之和
给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a2 + b2 = c. 示例1: 输入: 5 输出: True 解释: 1 * 1 + 2 * 2 = 5 示例2: 输入: 3 ...
- 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 ...
- 【Leetcode_easy】633. Sum of Square Numbers
problem 633. Sum of Square Numbers 题意: solution1: 可以从c的平方根,注意即使c不是平方数,也会返回一个整型数.然后我们判断如果 i*i 等于c,说明c ...
- 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 ...
- [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 平方数之和
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的 ...
- [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 ...
随机推荐
- 【REST详述及RESTful规范】
目录 Web服务交互 理解REST 什么是资源? 什么是URI.URL? 统一资源接口 资源的表述 状态转移 小结 "RESTful是一种软件的架构风格.设计风格,为客户端和服务端的交互提供 ...
- office自签名证书
在 Office安装目录,找到 SELFCERT 文件,双击打开填写名称,生成
- 「JSOI2015」串分割
「JSOI2015」串分割 传送门 首先我们会有一个贪心的想法:分得越均匀越好,因为长的绝对比短的大. 那么对于最均匀的情况,也就是 \(k | n\) 的情况,我们肯定是通过枚举第一次分割的位置,然 ...
- Python实现一个桌面版的翻译工具【新手必学】
Python 用了好长一段时间了,起初是基于对爬虫的兴趣而接触到的.随着不断的深入,慢慢的转了其它语言,毕竟工作机会真的太少了.很多技能长时间不去用,就会出现遗忘,也就有了整理一下,供初学者学习和 ...
- linux下的apue.3e安装[Unix环境高级编程]
近期正在看<Unix环境高级编程>一书,目前看了20多页,书中 有几个c的例程,于是想着,也让它运行一下,看看是否跟描述相符,做开发人员本应该这样,于是敲了一部分代码,然后编译,发现并不能 ...
- 如何让后加载的元素被一开始就有的css样式渲染成功(强制提升css优先级)
今天在做搜索框中的提示语下拉的时候,提示框把搜索框的底部的border遮住,导致看起来不是很美观: 因为下方的提示框是用js后加载的它的样式也是随着js一起加载的,而这个js和它的css我们是不能改动 ...
- 【visio】 设计
1."设计" 包含了 页面.布局和主题相关设置 2."页面设置" 包含:打印.绘制区域.打印区域.页面缩放.页属性以及替换文字. 替换文字 放在页面设置里,这个 ...
- 在linux环境下python与C++混合编程
参考:在linux环境下编译C++ 程序 linux下python3调用c代码或者python3调用c++代码 https://blog.csdn.net/u013179327/article/det ...
- JVM系列(三)之GC
什么是GC Java GC(Garbage Collection,垃圾收集,垃圾回收)机制,是Java与C++/C的主要区别之一,作为Java开发者,一般不需要专门编写内存回收和垃圾清理代码,对内存泄 ...
- vagrant up 报VirtualBox错误
Debug output $ $ vagrant.exe up ==> default: Checking if box 'janihur/ubuntu-1404-desktop' is up ...