167的变形题,也是用两个指针
题解:
class Solution:
def judgeSquareSum(self, c: int) -> bool:
a = 0
b = int(c ** 0.5)
while a <= b:
if a ** 2 + b ** 2 == c:
return True
elif a ** 2 + b ** 2 > c:
b = b-1
else:
a = a +1
return False
结果: