当前位置:网站首页>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;
}
边栏推荐
- CocoaPods could not find compatible versions for pod 'Firebase/CoreOnly'
- The inconsistency between the versions of dynamic library and static library will lead to bugs
- GNSS terminology
- Gartner released the prediction of eight major network security trends from 2022 to 2023. Zero trust is the starting point and regulations cover a wider range
- 【详细】快速实现对象映射的几种方式
- Basic process and testing idea of interface automation
- Dede collection plug-in free collection release push plug-in
- BiShe - College Student Association Management System Based on SSM
- 282. Stone consolidation (interval DP)
- Code Review关注点
猜你喜欢

The inconsistency between the versions of dynamic library and static library will lead to bugs

关于softmax函数的见解

Leetcode study - day 35

ThreeDPoseTracker项目解析

Unity | two ways to realize facial drive

【详细】快速实现对象映射的几种方式

False breakthroughs in the trend of London Silver

Who knows how to modify the data type accuracy of the columns in the database table of Damon

Opinions on softmax function

Finding the nearest common ancestor of binary search tree by recursion
随机推荐
VMware Tools installation error: unable to automatically install vsock driver
SCM Chinese data distribution
Recommended areas - ways to explore users' future interests
XSS learning XSS lab problem solution
Gartner released the prediction of eight major network security trends from 2022 to 2023. Zero trust is the starting point and regulations cover a wider range
Mysql--- query the top 5 students
Leetcode1961. 检查字符串是否为数组前缀
WGet: command line download tool
Development trend of Ali Taobao fine sorting model
Code Review关注点
False breakthroughs in the trend of London Silver
Leetcode1961. Check whether the string is an array prefix
Une image! Pourquoi l'école t'a - t - elle appris à coder, mais pourquoi pas...
Leetcode sword finger offer 59 - ii Maximum value of queue
The basic usage of JMeter BeanShell. The following syntax can only be used in BeanShell
[机缘参悟-39]:鬼谷子-第五飞箝篇 - 警示之二:赞美的六种类型,谨防享受赞美快感如同鱼儿享受诱饵。
VMware Tools安装报错:无法自动安装VSock驱动程序
一圖看懂!為什麼學校教了你Coding但還是不會的原因...
Dede collection plug-in free collection release push plug-in
Differences between standard library functions and operators