69. x 的平方根

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution:
def mySqrt(self, x: int) -> int:
left = 0
right = x
while left<=right:
half = left + (right-left)//2
if half*half == x:
return half
elif half*half > x:
right = half - 1
end = right
else:
left = half + 1
end = right
return end