当前位置:网站首页>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;
}
边栏推荐
- ADS-NPU芯片架构设计的五大挑战
- 什么是弱引用?es6中有哪些弱引用数据类型?js中的弱引用是什么?
- General operation method of spot Silver
- Recursive method converts ordered array into binary search tree
- Yii console method call, Yii console scheduled task
- Netease smart enterprises enter the market against the trend, and there is a new possibility for game industrialization
- Exciting, 2022 open atom global open source summit registration is hot
- VMware Tools installation error: unable to automatically install vsock driver
- 电气数据|IEEE118(含风能太阳能)
- 【第30天】给定一个整数 n ,求它的因数之和
猜你喜欢

Four commonly used techniques for anti aliasing

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

基於DVWA的文件上傳漏洞測試

Ordinary people end up in Global trade, and a new round of structural opportunities emerge

Blue Bridge Cup embedded stm32g431 - the real topic and code of the eighth provincial competition

Ubantu check cudnn and CUDA versions

VSphere implements virtual machine migration

现货白银的一般操作方法

ubantu 查看cudnn和cuda的版本

Hcip---ipv6 experiment
随机推荐
Mlsys 2020 | fedprox: Federation optimization of heterogeneous networks
About error 2003 (HY000): can't connect to MySQL server on 'localhost' (10061)
How does Huawei enable debug and how to make an image port
Study diary: February 13, 2022
什么是弱引用?es6中有哪些弱引用数据类型?js中的弱引用是什么?
Recursive method converts ordered array into binary search tree
普通人下场全球贸易,新一轮结构性机会浮出水面
Finding the nearest common ancestor of binary tree by recursion
Kotlin core programming - algebraic data types and pattern matching (3)
SPIR-V初窺
In the era of industrial Internet, we will achieve enough development by relying on large industrial categories
Vulhub vulnerability recurrence 74_ Wordpress
Tcpdump: monitor network traffic
VSphere implements virtual machine migration
IP storage and query in MySQL
基于DVWA的文件上传漏洞测试
Is chaozhaojin safe? Will it lose its principal
Obstacle detection
[day 30] given an integer n, find the sum of its factors
Cf:h. maximum and [bit operation practice + K operations + maximum and]