leetcode 69. Sqrt(x)
2016-03-14 13:52
369 查看
Implement
Compute and return the square root of x.
accepted
类似二分查找,夹逼思想(不要想歪了)
int sqrt(int x).
Compute and return the square root of x.
int mySqrt(int x) { if (x == 0) return 0; long long int xx = x; long long int up = xx; long long int down = 0; while (true) { if (up*up > xx) up = (up+down)/2; else { int t = down; down = up; up = 2 * up - t; if (up-down==1&&up*up>=xx||up==down) return up*up == x ? up : down; } } }
accepted
类似二分查找,夹逼思想(不要想歪了)
相关文章推荐
- SIOCSIFFLAGS: Operation not possible due to RF-kill
- 百度地图开发 android App 数字签名(SHA1)获取办法
- 前端分页效果
- https
- 欢迎使用CSDN-markdown编辑器
- 活动的生存周期
- WD mycloud 加载过慢的时候注意事项
- wmap安装过程的问题解决
- 【bzoj1857】[Scoi2010]传送带 三分法
- xml中出现The processing instruction target matching "[xX][mM][lL]" is not allowed.
- 网址链接收藏
- lintcode-medium-Add and Search Word
- layer用法
- select标签 style设置
- 安卓7.0权限及预览版问题
- [leetcode]Path Sum--巧用递归
- windows下mysql每天定时备份数据库几种方法
- JavaScript实现360度全景图片展示效果
- Git服务器搭建全过程分步详解
- java 4种内部类解析