当前位置:网站首页>Leetcode skimming questions_ Sum of squares
Leetcode skimming questions_ Sum of squares
2022-07-06 01:24:00 【Figure throne】
Title Description
Given a nonnegative integer c
, You have to decide if there are two integers a
and b
, bring a2 + b2 = c
.
Java resolvent
class Solution {
public boolean judgeSquareSum(int c) {
long a = 0;
int b = (int)Math.sqrt(c);
while(a <= b)
{
// a * a + b * b It is possible to surpass int Value range , Need to use long
if(a * a + b * b > c)
{
b--;
}
else if(a * a + b * b < c)
{
a++;
}
else
{
return true;
}
}
return false;
}
}
C resolvent
bool judgeSquareSum(int c){
long a = 0;
int b = (int)sqrt(c);
while(a <= b)
{
// a * a + b * b It is possible to surpass int Value range , Need to use long
if(a * a + b * b > c)
{
b--;
}
else if(a * a + b * b < c)
{
a++;
}
else
{
return true;
}
}
return false;
}
边栏推荐
- Vulhub vulnerability recurrence 75_ XStream
- 记一个 @nestjs/typeorm^8.1.4 版本不能获取.env选项问题
- Some features of ECMAScript
- VMware Tools installation error: unable to automatically install vsock driver
- 037 PHP login, registration, message, personal Center Design
- Leetcode 208. Implement trie (prefix tree)
- 普通人下场全球贸易,新一轮结构性机会浮出水面
- SCM Chinese data distribution
- The inconsistency between the versions of dynamic library and static library will lead to bugs
- PHP error what is an error?
猜你喜欢
MATLB|实时机会约束决策及其在电力系统中的应用
Five challenges of ads-npu chip architecture design
Dedecms plug-in free SEO plug-in summary
Idea sets the default line break for global newly created files
Recursive method to realize the insertion operation in binary search tree
【详细】快速实现对象映射的几种方式
Unity | 实现面部驱动的两种方式
leetcode刷题_反转字符串中的元音字母
leetcode刷题_验证回文字符串 Ⅱ
Fibonacci number
随机推荐
Vulhub vulnerability recurrence 75_ XStream
[day 30] given an integer n, find the sum of its factors
Nmap: network detection tool and security / port scanner
XSS learning XSS lab problem solution
Obstacle detection
Mlsys 2020 | fedprox: Federation optimization of heterogeneous networks
Unity VR resource flash surface in scene
电气数据|IEEE118(含风能太阳能)
Leetcode 208. Implement trie (prefix tree)
FFT learning notes (I think it is detailed)
SPIR-V初窥
Overview of Zhuhai purification laboratory construction details
Dedecms plug-in free SEO plug-in summary
Unity VR solves the problem that the handle ray keeps flashing after touching the button of the UI
普通人下场全球贸易,新一轮结构性机会浮出水面
SCM Chinese data distribution
Four dimensional matrix, flip (including mirror image), rotation, world coordinates and local coordinates
ORA-00030
Five challenges of ads-npu chip architecture design
Recursive method to realize the insertion operation in binary search tree