【leetcode】Sqrt(x)
来源:互联网 发布:node.js是什么 编辑:程序博客网 时间:2024/05/07 03:58
Sqrt(x)
Implement int sqrt(int x).
Compute and return the square root of x.
思路:
如果不知道二分之后左右的取法的话,可以找个实例进行推测。
class Solution {public: int mySqrt(int x) { if(x<=1) return x; int left=1, right=x; while(left<=right) { int mid=(left+right)/2; if(mid==x/mid) return mid; if(mid > x/mid) right=mid-1; else left=mid+1; } return right; }};
0 0
- LeetCode: Sqrt(x)
- LeetCode sqrt(x)
- [Leetcode] Sqrt(x)
- LeetCode :Sqrt(x)
- leetcode 53: Sqrt(x)
- [LeetCode] Sqrt(x)
- Leetcode 69 sqrt(x)
- [Leetcode] Sqrt(x)
- leetcode:Sqrt(x)
- 【leetcode】sqrt(int x)
- [LeetCode]Sqrt(x)
- [leetcode]Sqrt(x)
- LeetCode-Sqrt(x)
- [leetcode] Sqrt(x)
- [leetcode] Sqrt(x)
- LeetCode - Sqrt(x)
- leetcode之sqrt(x)
- LeetCode | Sqrt(x)
- 关于进程控制块PCB
- NSDate 的一些操作(比较、创建、在现有date加减一定时间等)
- "创业梦"的破碎
- python中文编码
- java中的常量
- 【leetcode】Sqrt(x)
- javascript面向对象思想做form表单验证 代码很精简哦
- Leetcode Sort Colors
- php为Apache指定工作目录(虚拟目录)
- 道路模型--linear-parabolic model
- 事件监听机制
- SpringMVC-05 处理模型数据
- greenDAO 使用初体验
- Binary Tree Preorder Traversal