当前位置:网站首页>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;
}
边栏推荐
- 2022年广西自治区中职组“网络空间安全”赛题及赛题解析(超详细)
- A picture to understand! Why did the school teach you coding but still not
- File upload vulnerability test based on DVWA
- [day 30] given an integer n, find the sum of its factors
- Vulhub vulnerability recurrence 74_ Wordpress
- [机缘参悟-39]:鬼谷子-第五飞箝篇 - 警示之二:赞美的六种类型,谨防享受赞美快感如同鱼儿享受诱饵。
- Zhuhai's waste gas treatment scheme was exposed
- Leetcode 208. Implement trie (prefix tree)
- 基於DVWA的文件上傳漏洞測試
- servlet(1)
猜你喜欢
激动人心,2022开放原子全球开源峰会报名火热开启
282. Stone consolidation (interval DP)
一圖看懂!為什麼學校教了你Coding但還是不會的原因...
Hcip---ipv6 experiment
1791. Find the central node of the star diagram / 1790 Can two strings be equal by performing string exchange only once
False breakthroughs in the trend of London Silver
Opinions on softmax function
3D模型格式汇总
JVM_ 15_ Concepts related to garbage collection
IP storage and query in MySQL
随机推荐
Leetcode daily question solution: 1189 Maximum number of "balloons"
JVM_ 15_ Concepts related to garbage collection
yii中console方法调用,yii console定时任务
Is chaozhaojin safe? Will it lose its principal
SSH login is stuck and disconnected
Netease smart enterprises enter the market against the trend, and there is a new possibility for game industrialization
电气数据|IEEE118(含风能太阳能)
3D model format summary
Code Review关注点
什么是弱引用?es6中有哪些弱引用数据类型?js中的弱引用是什么?
A Cooperative Approach to Particle Swarm Optimization
Unity VR solves the problem that the handle ray keeps flashing after touching the button of the UI
Alibaba-Canal使用详解(排坑版)_MySQL与ES数据同步
MATLB|实时机会约束决策及其在电力系统中的应用
【第30天】给定一个整数 n ,求它的因数之和
有谁知道 达梦数据库表的列的数据类型 精度怎么修改呀
Mysql--- query the top 5 students
Unity | 实现面部驱动的两种方式
Blue Bridge Cup embedded stm32g431 - the real topic and code of the eighth provincial competition
【详细】快速实现对象映射的几种方式