Two Pointers
class Solution:
def judgeSquareSum(self, c: int) -> bool:
l, r = 0, int(c**0.5)
while l<=r:
s = l*l + r*r
if s==c:
return True
elif s<c:
l += 1
else:
r -= 1
return False
Other
class Solution:
def judgeSquareSum(self, c: int) -> bool:
for i in range(int(c**0.5)+1):
n = c-i*i
if int(n**0.5)**2==n:
return True
return False