leetcode69---Sqrt(x)(求x的平方根)
来源:互联网 发布:php开源投票系统 编辑:程序博客网 时间:2024/04/28 15:35
问题描述:
Implement int sqrt(int x).
Compute and return the square root of x.
问题求解:
二分法。O(logN)
class Solution {public: int mySqrt(int x) { long long low =1; long long high=x; long long tmp;//用于和x比较 while(low < high) {//二分法查找1~x里边的数,平方为tmp,与x比较 long long mid = low + (high-low)/2; tmp = mid*mid; if(tmp==x) return mid; else if(tmp > x) high=mid-1; else low=mid+1; } tmp = high*high; if(tmp > x) return high-1; else return high; }};
0 0
- leetcode69---Sqrt(x)(求x的平方根)
- Sqrt(x) 求平方根
- LeetCode69 Sqrt(x)**
- [Java]Leetcode69 Sqrt(x)
- leetcode69. Sqrt(x)
- Leetcode69. Sqrt(x)
- leetcode69. Sqrt(x)
- leetcode69. Sqrt(x)
- leetcode69: Sqrt(x)
- LeetCode69. Sqrt(x)
- LeetCode69 Sqrt(x)
- leetcode69---Sqrt(x)
- Sqrt(x) 求平方根@LeetCode
- LeetCode69——Sqrt(x)
- Leetcode刷题记—— 69. Sqrt(x)(求整数x的平方根)
- 141.Sqrt(x)-x的平方根(容易题)
- LintCode Sqrt(x) x的平方根
- LintCode:Sqrt(x) x的平方根
- 【rabbitmq】 com.rabbitmq.client.AlreadyClosedException: channel is already closed due to channel erro
- Android Studio查看SVN历史记录不能正确显示中文
- ceph 学习笔记
- APK瘦身方案
- J2EE的基础学习_jsp_servlet_获得连接池
- leetcode69---Sqrt(x)(求x的平方根)
- C++Primer第五版 12.1.6节练习
- 自定义键盘输入框的实现
- @Component注解
- cms系统资源路径引入
- 【LEETCODE】81-Search in Rotated Sorted Array II [Python]
- RobotFrameWork(一)robotfamework在centos下headless无界面安装
- Pandas学习笔记(一)
- ios 移动端架构浅析