标签:math for solution imp 示例 存在 int turn bool
给定一个非负整数 c
,你要判断是否存在两个整数 a
和 b
,使得 a2 + b2 = c。
示例1:
输入: 5
输出: True
解释: 1 * 1 + 2 * 2 = 5
示例2:
输入: 3
输出: False
class Solution {
public boolean judgeSquareSum(int c) {
int i = 0, j = (int)Math.sqrt(c);
while(i <= j){
int powSum = i * i + j * j;
if (powSum == c){
return true;
}else if(powSum > c){
j --;
}else{
i ++;
}
}
return false;
}
}
import . "math"
func judgeSquareSum(c int) bool {
i := 0
j := int(Sqrt(float64(c)))
for i <= j {
powSum := i * i + j * j
if powSum == c{
return true
}else if powSum > c {
j --
}else{
i ++
}
}
return false
}
标签:math for solution imp 示例 存在 int turn bool
原文地址:https://www.cnblogs.com/Tu9oh0st/p/10961262.html