633. 平方数之和

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution:
def judgeSquareSum(self, c: int) -> bool:
# 经典的双指针问题,但是不是二分法。
left = 0
right = int(sqrt(c))
while left<=right:
if left*left + right*right == c:
return True
elif left*left + right*right > c:
right -= 1
else:
left += 1
return False