Leetcode134: Sqrt(x)
2015-11-02 17:12
375 查看
Implement
Compute and return the square root of x.
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 l = 1; int r = x/2; while(l<=r) { int mid = (r+l)/2; if(mid== x/mid) return mid; else if(mid > x/mid) r = mid-1; else l = mid+1; } return r; } };
相关文章推荐
- 编程学习小笔记
- android 实现每天7点到21点定时提示的功能
- 清除mysql表中数据
- 使用accumulate出现error c 2064错误
- Android学习路线权威指南
- ZABBIX自定义用户KEY与参数USERPARAMETERS监控脚本输出
- Oracle 修改一行数据内存主要变化
- ORA-04030
- scrollTo(String text) and scrollToExact(String text) method of Android Driver not working
- 第十周项目1 - 二叉树算法库
- 第十周 项目3-利用二叉树遍历思想解决问题
- centos7安装配置svn
- js数组去除重复方法添加
- 第九周项目4-广义算法库应用(2)
- 第八周实践项目~建立链串算法库
- 用wireshark抓包IOS优酷app
- VIM Resources
- 三个文件每行去重且保持原序叠加
- Spring随笔5
- Pjax调用