leetcode——69——Sqrt(x)
来源:互联网 发布:淘宝联盟qq群推广技巧 编辑:程序博客网 时间:2024/06/06 00:59
Implement int sqrt(int x)
.
Compute and return the square root of x.
考虑到不是完全平方数的情况
class Solution {public: int mySqrt(int x) { if(x <= 0) return 0; int low = 1; int high = x; int mid; while (low <= high) { mid = (high + low)/ 2; if ((x / mid >= mid) && ((mid + 1) > x / (mid + 1))) { //to avoid overflow return mid; } else if ( x / mid < mid ) { high = mid - 1; } else { low = mid + 1; } } return -1; }};
0 0
- LeetCode —— Sqrt(x)
- LeetCode——Sqrt(x)
- LeetCode——Sqrt(x)
- leetcode 069 —— Sqrt(x)
- Hold住Leetcode—— Sqrt(x)
- Leetcode——69. Sqrt(x)
- LeetCode 之 Sqrt(x) — C 实现
- leetcode——69——Sqrt(x)
- LeetCode 69 — Sqrt(x)(C++ Java Python)
- 数据结构与算法[LeetCode]——sqrt(x)
- Leetcode代码学习周记——Sqrt(x)
- LeetCode69——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)
- 学习 Spark Streaming 的重要性
- jQuery重置select
- 【机房重构】Sqlhelper类解读
- Tomcat源码分析--启动过程
- 周易六十四卦——噬嗑卦
- leetcode——69——Sqrt(x)
- poj2663 分治
- JAVA集合类详解
- apk基础-反编译、打包、签名
- C++异常机制
- mybatis SQL性能调优
- Android中的线程和线程池
- hihocoder #1035 : 自驾旅行 III
- ReadWriteLock用法