LeetCode69 x的平方根 (二分)
class Solution(object):
def mySqrt(self, x):
"""
:type x: int
:rtype: int
"""
l, r, ans = 0, x, -1
while l <= r:
mid = (l + r) // 2
if mid * mid <= x:
ans = mid
l = mid + 1
else:
r = mid - 1
return ans