Leetcode 69 Sqrt(x)
来源:互联网 发布:kk录制软件 编辑:程序博客网 时间:2024/06/03 20:59
Implement int sqrt(int x).
Compute and return the square root of x.
x is guaranteed to be a non-negative integer.
class Solution {public: int mySqrt(int x) { int begin = 0; int end = x; // (begin + end) / 2 向左偏,所以end 可能未被检测 if (1 == x) return 1; while (end - begin > 1) { int mid = (begin + end) / 2; if (mid == x / mid) return mid; else if (mid > x / mid) end = mid; else begin = mid; } return begin; }};
参考后
牛顿法
class Solution {public: int mySqrt(int x) { long ret = x; while (ret * ret > x) { ret = (ret * ret + x) / (2 * ret); } return ret; }};
阅读全文
0 0
- 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)
- [Leetcode]#69 Sqrt(x)
- 【leetcode】【69】Sqrt(x)
- Android Studio如何修改快捷键
- Ajax工作原理
- MyBatis高级查询
- 吴恩达Coursera深度学习课程 DeepLearning.ai 提炼笔记(4-3)-- 目标检测
- Mariadb的安装和基本操作
- Leetcode 69 Sqrt(x)
- PHP中$_POST[]函数的作用
- Nginx 学习。
- Flink On Yarn 异常排除过程
- hibernate一级缓存--即session级别缓存.docx
- web开发方面会遇到哪些缓存?分别如何优化
- javascript中的事件一
- MyBatis缓存配置
- 数据挖掘资源