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 ...
 
随机推荐
- php的str_pad()函数
			
实例 填充字符串的右侧,到30个字符的新长度 <?php $str = "Hello World"; echo str_pad($str,30,"."); ...
 - 忽视自身问题并“积极甩锅”,新氧CEO金星还要脸吗?
			
编辑 | 于斌 出品 | 于见(mpyujian) "互联网医美第一股"新氧果然还是爆雷了. 说"果然"是因为于见曾经针对新氧目前的商业模式进行过分析,认为以新 ...
 - python--小游戏(循环+随机)
			
1 import time 2 import random 3 4 player_victory = 0 5 enemy_victory = 0 6 a1 = True 7 while a1: 8 f ...
 - P1028
			
一开始没看懂题,看了题解才明白的 = =.思路是,先找规律,会发现有重合部分,利用这些重合部分,写出递推公式. num = 0 时,只有 1 种组合: num = 1 时,只有 1 种组合: num ...
 - 6.Python字符串
			
#header { display: none !important; } } #header-spacer { width: 100%; visibility: hidden; } @media p ...
 - 如何使html中的元素不被选中
			
有时候,为了提高用户的体验度,需要使网页中的部分内容防误操作,不被选中,比如今天的商城项目中的一个细节部分: + —号其实是a标签做的,当连续点击多次,就会使符号被选中,这样感觉起来不太好,于是查找解 ...
 - 实现简单HttpServer案例
			
<html> <head> <title>第一个表单</title> </head> <body> <pre> me ...
 - 引入C/C++动态库
			
[DllImport("SocketAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = t ...
 - 常见排序的Java实现
			
插入排序 1.原理:在有序数组中从后向前扫描找到要插入元素的位置,将元素插入进去. 2.步骤:插入元素和依次和前一个元素进行比较,若比前一个元素小就交换位置,否则结束循环. 3.代码: package ...
 - java程序设计课期中考试——数据库的增删改查和简单的js界面
			
首先是设计思路,对于数据库的增删改查,我们借助Ecilipse来进行前端和后端的编写.Ecilipse是可以进行java web项目的操作的. 前端,我们选择用使用jsp,所谓的jsp就是可以嵌入其他 ...