一),二分法思想:
1,Sqrt(x) (x 的平方根):
英文版:https://leetcode.com/problems/sqrtx/
中文版:https://leetcode-cn.com/problems/sqrtx/@TOC
class Solution:
def mySqrt(self, x: int) -> int:
if x == 0:
return 0
l = 1
r = x
while l <= x:
res = (l + r) // 2
s = res ** 2
if s <= x < (res + 1)**2:
return res
if s < x:
l = res
if s > x:
r = res