Sqrt(x)
Example
Solution
class Solution:
"""
@param x: An integer
@return: The sqrt of x
"""
def sqrt(self, x):
if x <= 0:
return 0
start, end = 1, x
while start + 1 < end:
mid = (start + end) / 2
if mid * mid <= x:
start = mid
else:
end = mid
return startLast updated