题意:给定一个非负整数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(双指针)的更多相关文章

  1. Leetcode633.Sum of Square Numbers平方数之和

    给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a2 + b2 = c. 示例1: 输入: 5 输出: True 解释: 1 * 1 + 2 * 2 = 5 示例2: 输入: 3 ...

  2. 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 ...

  3. 【Leetcode_easy】633. Sum of Square Numbers

    problem 633. Sum of Square Numbers 题意: solution1: 可以从c的平方根,注意即使c不是平方数,也会返回一个整型数.然后我们判断如果 i*i 等于c,说明c ...

  4. 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 ...

  5. [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 ...

  6. [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 ...

  7. LeetCode算法题-Sum of Square Numbers(Java实现)

    这是悦乐书的第276次更新,第292篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第144题(顺位题号是633).给定一个非负整数c,判断是否存在两个整数a和b,使得a的 ...

  8. [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 ...

  9. 【LeetCode】633. Sum of Square Numbers

    Difficulty: Easy  More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/sum-of-square-n ...

随机推荐

  1. red hat 报错:apt-get:找不到命令

    Linux有两个系列:一个是RedHat系列,一个是Debian系列. RedHat系列:Redhat.Centos.Fedora等 Debian系列:Debian.Ubuntu等 RedHat 系列 ...

  2. 统计字符在字符串中第n次出现的位置

    输入一个字符串s,一个数字n和一个字符c,统计这个字符c在字符串s中第n次出现的位置 输入格式: 输入3行.第1行是字符串s,第2行是数字n,第3行是被查找的字符c. 输出格式: 第n个字符在字符串中 ...

  3. ZOJ1002 —— 深度优先搜索

    ZOJ1002 —— Fire net Time Limit: 2000 ms Memory Limit: 65536 KB Suppose that we have a square city wi ...

  4. 超好用的免费Redis客户端

    Redis这款基于内存的键值对(key-vlaue)数据库,自带了一个基于命令行式的管理工具redis-cli,但是使用起来并不方便.虽然现在有了许多的图形化管理工具,有些需要收费,有些不好用.最终还 ...

  5. 一周搞定模拟电路_P5_基本放电电路记录

    1.原始基本放大电路 2.改变Rb,Rb由200kΩ变为100kΩ 3 4

  6. Foreach报错

    List<String> a = new ArrayList<String>(); 2 a.add("1"); 3 a.add("2") ...

  7. 安装搭建appium运行环境

    整体步骤: 1.安装appium依赖的Python包(Appium-Python-Client): 2.安装Appium Desktop(集成了appium server和node.js,所以不需要额 ...

  8. AMD R7 2700X 安装虚拟机

    自己组装的台式机,选用的是微星X470主板,该主板默认的虚拟化技术是关闭的,在bios中也不太容易找到,具体方法如下. [开机或重启]--[按住DEL进入BIOS]--[高级模式F7]--[选择OC] ...

  9. MYSQL命令练习及跳过数据库密码进行密码重新设置

        2.看当前所有数据库:show databases; 3.进入mysql数据库:use mysql; 4.查看mysql数据库中所有的表:show tables; 5.查看user表中的数据: ...

  10. DreamWeaver CC 中的回车

    在Dreamweaver CC中换行有两种: 第一种是在设计视图中直接回车,对应的代码是<p>标签,即新生成一个段落. (注:在DreamWeaver CC编辑的代码中,按下回车相当于 ) ...