二分查找
class Solution:
def mySqrt(self, x: int) -> int:
if x == 0:
return 0
elif x == 1:
return 1
end = x // 2 + 1
print(end)
start = 0
while True:
temp = (end + start) // 2
print(temp)
if temp*temp == x or (temp*temp < x and (temp+1)*(temp+1) >x):
return temp
elif temp*temp < x :
start = temp + 1
elif temp*temp > x:
end = temp - 1