1、二分查找
class Solution:
def mySqrt(self, x: int) -> int:
# 思路:二分查找
left,right = 0,x
while left <= right:
mid = left+(right-left)//2
temp = mid*mid
if temp == x or (temp<x and (mid+1)*(mid+1)>x):
return mid
elif temp < x:
left = mid+1
else:
right = mid-1
2、官方给的利用对数函数求解(其实没必要哈哈)
3、牛顿迭代法(没看懂)