class Solution: def isPerfectSquare(self, num: int) -> bool: left, right = 0, num while left <= right: mid = int(left + (right - left)/2) if mid**2 == num: return True elif mid**2 > num: right = mid - 1 elif mid**2 < num: left = mid + 1 return False