当前位置:网站首页>leetcode刷题_平方数之和
leetcode刷题_平方数之和
2022-07-06 01:19:00 【身影王座】
题目描述
给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a2 + b2 = c 。

Java解决方法
class Solution {
public boolean judgeSquareSum(int c) {
long a = 0;
int b = (int)Math.sqrt(c);
while(a <= b)
{
// a * a + b * b有可能超过int取值范围,需要用long
if(a * a + b * b > c)
{
b--;
}
else if(a * a + b * b < c)
{
a++;
}
else
{
return true;
}
}
return false;
}
}
C解决方法
bool judgeSquareSum(int c){
long a = 0;
int b = (int)sqrt(c);
while(a <= b)
{
// a * a + b * b有可能超过int取值范围,需要用long
if(a * a + b * b > c)
{
b--;
}
else if(a * a + b * b < c)
{
a++;
}
else
{
return true;
}
}
return false;
}
边栏推荐
- golang mqtt/stomp/nats/amqp
- Daily practice - February 13, 2022
- ADS-NPU芯片架构设计的五大挑战
- Threedposetracker project resolution
- Nmap: network detection tool and security / port scanner
- Vulhub vulnerability recurrence 75_ XStream
- False breakthroughs in the trend of London Silver
- 在产业互联网时代,将会凭借大的产业范畴,实现足够多的发展
- SPIR-V初窺
- Who knows how to modify the data type accuracy of the columns in the database table of Damon
猜你喜欢

关于softmax函数的见解

Finding the nearest common ancestor of binary tree by recursion

电气数据|IEEE118(含风能太阳能)

Cf:c. the third problem
![[pat (basic level) practice] - [simple mathematics] 1062 simplest fraction](/img/b4/3d46a33fa780e5fb32bbfe5ab26a7f.jpg)
[pat (basic level) practice] - [simple mathematics] 1062 simplest fraction

Exciting, 2022 open atom global open source summit registration is hot

Beginner redis

037 PHP login, registration, message, personal Center Design

Four commonly used techniques for anti aliasing

Vulhub vulnerability recurrence 75_ XStream
随机推荐
现货白银的一般操作方法
Tcpdump: monitor network traffic
WGet: command line download tool
Ubantu check cudnn and CUDA versions
Blue Bridge Cup embedded stm32g431 - the real topic and code of the eighth provincial competition
yii中console方法调用,yii console定时任务
基于DVWA的文件上传漏洞测试
After 95, the CV engineer posted the payroll and made up this. It's really fragrant
Four commonly used techniques for anti aliasing
In the era of industrial Internet, we will achieve enough development by relying on large industrial categories
servlet(1)
File upload vulnerability test based on DVWA
cf:H. Maximal AND【位运算练习 + k次操作 + 最大And】
Huawei converged VLAN principle and configuration
Leetcode1961. Check whether the string is an array prefix
Cglib dynamic agent -- example / principle
Live broadcast system code, custom soft keyboard style: three kinds of switching: letters, numbers and punctuation
IP storage and query in MySQL
282. Stone consolidation (interval DP)
C language programming (Chapter 6 functions)