633. Sum of Square Numbers【Easy】【双指针-是否存在两个数的平方和等于给定目标值】
Given a non-negative integer c
, your task is to decide whether there're two integers a
and b
such that a2 + b2 = c.
Example 1:
Input: 5
Output: True
Explanation: 1 * 1 + 2 * 2 = 5
Example 2:
Input: 3
Output: False
class Solution {
public boolean judgeSquareSum(int c) {
int i = 0, j = (int)Math.sqrt(c);
while(i <= j) {
int sum = i*i + j*j;
if(sum == c) {
return true;
} else if(sum > c) {
j--;
} else {
i++;
}
}
return false;
}
}
633. Sum of Square Numbers【Easy】【双指针-是否存在两个数的平方和等于给定目标值】的更多相关文章
- 【Leetcode_easy】633. Sum of Square Numbers
problem 633. Sum of Square Numbers 题意: solution1: 可以从c的平方根,注意即使c不是平方数,也会返回一个整型数.然后我们判断如果 i*i 等于c,说明c ...
- 【LeetCode】633. Sum of Square Numbers 解题报告(python & Java & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 列表生成式 循环 日期 题目地址:https ...
- 【LeetCode】633. Sum of Square Numbers
Difficulty: Easy More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/sum-of-square-n ...
- [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 ...
- LeetCode633. Sum of Square Numbers(双指针)
题意:给定一个非负整数c,确定是否存在a和b使得a*a+b*b=c. class Solution { typedef long long LL; public: bool judgeSquareSu ...
- #Leetcode# 633. Sum of Square Numbers
https://leetcode.com/problems/sum-of-square-numbers/ Given a non-negative integer c, your task is to ...
- LeetCode 633. Sum of Square Numbers平方数之和 (C++)
题目: Given a non-negative integer c, your task is to decide whether there're two integers a and b suc ...
- 633. Sum of Square Numbers
static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...
- 633. Sum of Square Numbers 是否由两个完全平方数构成
[抄题]: Given a non-negative integer c, your task is to decide whether there're two integers a and b s ...
随机推荐
- 前端多层回调问题解决方案之$.Deferred
javascript引擎是单线程的,但是通过异步回调可以实现IO操作并行执行能力,当业务逻辑复杂的时候我们就进入回调地狱. 本文讲得ajax是在jquery1.5以前的版本,目的旨在让我们理解延迟对象 ...
- javascript拖拽原理与简单实现方法[demo]
美国人有一句常用的俗语—“Re-inventing the Wheel”,从字面上来解释就是“重新发明轮子”.可是轮子早已问世,再要去发明岂非劳而无功? 产品经理发下需求,实施者再到网上搜索代码,也许 ...
- 【BZOJ4514】【SDOI2016】数字配对 [费用流]
数字配对 Time Limit: 10 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description 有 n 种数字,第 i 种数字是 ...
- 【CodeForces】835D Palindromic characteristics
[题意]给你一个串,让你求出k阶回文子串有多少个.k从1到n.k阶子串的定义是:子串本身是回文串,而且它的左半部分也是回文串. [算法]区间DP [题解]涉及回文问题的区间DP都可以用类似的写法,就是 ...
- C++正则表达式例子
给了策划配置公式的地方,需要将策划配置的公式文本转化为可执行的脚本代码:比如:self->mHp*2+target->2mMp*GetHit()+ self_mon->4mDan/1 ...
- NYOJ 1237 最大岛屿 (深搜)
题目链接 描述 神秘的海洋,惊险的探险之路,打捞海底宝藏,激烈的海战,海盗劫富等等.加勒比海盗,你知道吧?杰克船长驾驶着自己的的战船黑珍珠1号要征服各个海岛的海盜,最后成为海盗王. 这是一个由海洋. ...
- 使用SQL Server连接xml接口,读取并解析数据
--数据源格式,放到任意程序中部署接口即可--<Data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmln ...
- 【Windows使用笔记】使Onedrive同步任意文件夹
因为度盘实在是有点垃圾,经常看的剧之类的或者其他软件资源啥的动不动就被封. 所以跑去某宝买了一个5T的企业子账号,安全性不清楚,重要的隐私数据反正都用移动硬盘备份了.主要就是存一些资源性的文件吧.而且 ...
- sicily 1046. Plane Spotting
1046. Plane Spotting Time Limit: 1sec Memory Limit:32MB Description Craig is fond of planes. Mak ...
- 【数位dp入门】【HDU2089】62
为了我的点歪的技能树…… 所以开始补一些sb的东西…… #include<bits/stdc++.h> typedef long long ll; using namespace std; ...