367. 有效的完全平方数

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution:
def isPerfectSquare(self, num: int) -> bool:
left = 1
right = num
while left<=right:
half = left + (right-left)//2
if half*half == num:
return True
elif half*half > num:
right = half - 1
else:
left = half + 1
return False