2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
This is a typical double pointer question. I don’t know why LeetCode puts this question in the binary category?
need to knowmath.ceil()
is rounded up;
class Solution:
def judgeSquareSum(self, c: int) -> bool:
upper = math.ceil(sqrt(c))
print(upper)
left, right = 0, upper
while(left <= right):
if left * left + right * right > c:
right-=1
elif left * left + right * right < c:
left+=1
else:
return True
return False