chiyeuemthoi
Senior Member
Code:
import math
class Solution:
def judgeSquareSum(self, c: int) -> bool:
def check(x):
return math.sqrt(x).is_integer()
def binarySearch(l , r , x):
if not check(x): return False
while l <= r:
mid = (l + r) // 2
if mid == x:
return True
elif mid > x: r = mid - 1
else: l = mid + 1
return False
for l in range(0 , int(math.sqrt(c) + 1)):
if binarySearch(0 , c , c - l * l): return True
return False