633. 平方数之和
为保证权益,题目请参考 633. 平方数之和(From LeetCode).
解决方案1
Python
python
from math import sqrt
class Solution:
def judgeSquareSum(self, c: int) -> bool:
a = 0
b = int(sqrt(c))
while a < b:
n = a ** 2 + b ** 2
if n == c:
return True
elif n < c:
a += 1
else:
b -= 1
return False
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17