2018-05-08 Leetcode 69. Sqrt(x) 原思路 (Time Exceed)遍历 0—> x, 直到遇到 sqrt(x) 123456789class Solution: def mySqrt(self, x): """ :type x: int :rtype: int """ for i in range(x+1): if (i+1)**2 > x: return i ImprovementUse Binary Search, 降低搜索时间 1234567891011121314151617181920212223class Solution: # dfs def mySqrt(self, x): """ :type x: int :rtype: int """ def dfs (start,end): # int(float) method, 去小数点后面的数 mid = int((start + end)/2) if mid **2 > x: return dfs(start,mid-1) else: if (mid+1) ** 2 > x: return mid else: return dfs(mid+1,end) return dfs(0,x) Newer 203. Remove Linked List Elements Older float to int & float 精度转换