当前位置:网站首页>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
- Basic process and testing idea of interface automation
- Docker compose配置MySQL并实现远程连接
- Live broadcast system code, custom soft keyboard style: three kinds of switching: letters, numbers and punctuation
- How to get all sequences in Oracle database- How can I get all sequences in an Oracle database?
- Zhuhai laboratory ventilation system construction and installation instructions
- Development trend of Ali Taobao fine sorting model
- How to extract MP3 audio from MP4 video files?
- Unity VR solves the problem that the handle ray keeps flashing after touching the button of the UI
- In the era of industrial Internet, we will achieve enough development by relying on large industrial categories
猜你喜欢
测试/开发程序员的成长路线,全局思考问题的问题......
ADS-NPU芯片架构设计的五大挑战
Huawei Hrbrid interface and VLAN division based on IP
DOM introduction
电气数据|IEEE118(含风能太阳能)
2020.2.13
About error 2003 (HY000): can't connect to MySQL server on 'localhost' (10061)
Une image! Pourquoi l'école t'a - t - elle appris à coder, mais pourquoi pas...
VMware Tools安装报错:无法自动安装VSock驱动程序
现货白银的一般操作方法
随机推荐
Alibaba-Canal使用详解(排坑版)_MySQL与ES数据同步
SSH login is stuck and disconnected
[day 30] given an integer n, find the sum of its factors
internship:项目代码所涉及陌生注解及其作用
Who knows how to modify the data type accuracy of the columns in the database table of Damon
Vulhub vulnerability recurrence 74_ Wordpress
How to get the PHP version- How to get the PHP Version?
Idea sets the default line break for global newly created files
【已解决】如何生成漂亮的静态文档说明页
What is the most suitable book for programmers to engage in open source?
leetcode刷题_反转字符串中的元音字母
What is weak reference? What are the weak reference data types in ES6? What are weak references in JS?
Obstacle detection
BiShe - College Student Association Management System Based on SSM
Superfluid_ HQ hacked analysis
About error 2003 (HY000): can't connect to MySQL server on 'localhost' (10061)
JVM_ 15_ Concepts related to garbage collection
Vulhub vulnerability recurrence 75_ XStream
Leetcode1961. 检查字符串是否为数组前缀
Electrical data | IEEE118 (including wind and solar energy)