The Solution to LeetCode 69 Sqrt(x)
来源:互联网 发布:钱咖淘宝返利 编辑:程序博客网 时间:2024/05/20 03:37
Question:
Run code results:
Implement int sqrt(int x)
.
Compute and return the square root of x.
思路:本题采用二分法进行求解。Answer:
class Solution {public: int mySqrt(int x) { int low=0; int high=x; int mid=0; if(x<=1) { return x; } while(low+1<high) { mid = low + (high-low)/2; if(mid > x/mid) { high = mid; } else if(mid < x/mid) { low = mid; } else { return mid; } } return low; }};
Run code results:
Your input
17
Your answer
4
Expected answer
4
0 0
- The Solution to LeetCode 69 Sqrt(x)
- leetcode 69 implement the 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)
- Sqrt(x) - LeetCode 69
- leetcode 69:Sqrt(x)
- LeetCode---(69)Sqrt(x)
- Leetcode #69 Sqrt(x)
- LeetCode(69) Sqrt(x)
- leetcode 69: Sqrt(x)
- Leetcode#69||Sqrt(x)
- 使用 PureMVC 和 Cocos2d-js 构建游戏项目 II
- 安卓组件------列表选择框
- easyui仿百度搜索提示框
- HashMap在Java里是怎么工作的
- 解析数论引论 第2章 数论函数和狄利克雷乘积
- The Solution to LeetCode 69 Sqrt(x)
- 德州仪器TI CC2640R2F器件的命名规则
- [机器学习]机器学习之Python之NumPy数学库的介绍
- Dialog设置为点击空白处/点击按钮后 不消失
- MySQL中group_concat函数
- MySQL使用小坑总结(一)
- Hibernate------>JDBC--->优化版连接(jdbcUtil工具)
- swift 3.0 webview与JS的交互
- 对程序比较好的网站