[勇者闯LeetCode] 69. Sqrt(x)
2017-03-05 21:03
603 查看
[勇者闯LeetCode] 69. Sqrt(x)
Description
Implementint sqrt(int x).
Compute and return the square root o x.
Information
Tags: Binary Search | MatchDifficulty: Easy
Solution
使用二分搜索,算法复杂度为O(logN).class Solution(object): def mySqrt(self, x): """ :type x: int :rtype: int """ if x == 0: return 0 start, end = 1, x while (end >= start): mid = start + (end - start) // 2 s = x // mid if (mid == s): return mid elif (mid < s): start = mid + 1 else: end = mid - 1 return end
相关文章推荐
- The Solution to LeetCode 69 Sqrt(x)
- [Java]Leetcode69 Sqrt(x)
- LeetCode-69-Sqrt(x) Python要用math.sqrt()
- Leetcode 69 Sqrt(x) 求x开根号的整数部分
- Leetcode 69. Sqrt(x) 开根号 解题报告
- Leetcode刷题记—— 69. Sqrt(x)(求整数x的平方根)
- [LeetCode-69] Sqrt(x)(求解平方根)
- [leetcode]69. Sqrt(x)
- LeetCode 69. Sqrt(x)
- [LeetCode] 69. Sqrt(x)
- LeetCode 69. Sqrt(x)
- 【LeetCode】69. Sqrt(x) 二分查找实现开平方函数
- leetcode 69 Sqrt(x)
- LeetCode 69. Sqrt(x)
- [LeetCode]--69. Sqrt(x)
- Leetcode 69. Sqrt(x) 解题报告【C库函数sqrt(x)模拟-求平方根】
- LeetCode-69. Sqrt(x)
- LeetCode 69 Sqrt(x)
- 【LeetCode 69】Sqrt(x)
- Leetcode 69 Sqrt(x)