69. Sqrt(x) - LeetCode
Question
Solution
题目大意:
求一个数的平方根
思路:
二分查找
Python实现:
def sqrt(x):
l = 0
r = x + 1
while l < r:
m = l + (r - l) // 2
if m * m > x:
r = m
else:
l = m + 1
return l - 1