LeetCode 69. Sqrt(x),求根算法
来源:互联网 发布:nba2kol乔丹隐藏数据 编辑:程序博客网 时间:2024/05/29 07:21
69. Sqrt(x)
Implement int sqrt(int x)
.
Compute and return the square root of x.
Subscribe to see which companies asked this question
这道题要找x的平方根,x的平方根肯定小于x/2。要在[1,x/2]有序序列当中找一个数,用二分法:
public int mySqrt(int x) {long high = (x / 2) + 1;long low = 0;while (high >= low) {long mid = (high + low) / 2;if (mid * mid == x)return (int)mid;else if (mid * mid > x)high = mid - 1;elselow = mid + 1;}return (int)high;}
1 0
- 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)
- 【LeetCode】69. Sqrt(x)
- 69. Sqrt(x) LeetCode
- [leetcode] 69. Sqrt(x)
- leetcode 69. Sqrt(x)
- LeetCode 69. Sqrt(x)
- LeetCode 69. Sqrt(x)
- leetcode-69. Sqrt(x)
- [leetcode]69. Sqrt(x)
- Java接受输入参数
- 合并多个有序链表
- MFC-自绘控件(CRadio篇)
- 推荐 10 个超棒的 CSS3 代码生成工具
- POJ 3159
- LeetCode 69. Sqrt(x),求根算法
- 第四次上机实践项目-项目3-时间类-(1)
- QT 菜单栏,工具栏操作
- Java-LinkedHashMap源码解读
- hdoj Super Jumping! Jumping! Jumping! 1087 (DP求单调递增最大值)
- C++模板堆排序
- BZOJ1927星际竞速
- java线程同步——CountDownLatch
- Unit Test、 UI Test