当前位置:网站首页>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;
}
边栏推荐
- Leetcode study - day 35
- After 95, the CV engineer posted the payroll and made up this. It's really fragrant
- Huawei converged VLAN principle and configuration
- [pat (basic level) practice] - [simple mathematics] 1062 simplest fraction
- 在产业互联网时代,将会凭借大的产业范畴,实现足够多的发展
- Mysql--- query the top 5 students
- 记一个 @nestjs/typeorm^8.1.4 版本不能获取.env选项问题
- Three methods of script about login and cookies
- Mobilenet series (5): use pytorch to build mobilenetv3 and learn and train based on migration
- 关于softmax函数的见解
猜你喜欢
随机推荐
SPIR-V初窺
Leetcode1961. Check whether the string is an array prefix
SCM Chinese data distribution
Hcip---ipv6 experiment
黄金价格走势k线图如何看?
Dedecms plug-in free SEO plug-in summary
【第30天】给定一个整数 n ,求它的因数之和
Use of crawler manual 02 requests
Huawei converged VLAN principle and configuration
Opinions on softmax function
IP storage and query in MySQL
How to get the PHP version- How to get the PHP Version?
Differences between standard library functions and operators
【已解决】如何生成漂亮的静态文档说明页
GNSS terminology
ThreeDPoseTracker项目解析
Electrical data | IEEE118 (including wind and solar energy)
Live video source code, realize local storage of search history
程序员搞开源,读什么书最合适?
测试/开发程序员的成长路线,全局思考问题的问题......