[leetcode] Sqrt(x)
来源:互联网 发布:spss数据分析案例 编辑:程序博客网 时间:2024/06/10 02:20
From : https://leetcode.com/problems/sqrtx/
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; if(x <= 3) return 1; long long start = 1, end = x/2; while(start <= end) { long long mid = (start + end) >> 1; if(mid*mid <= x && (mid+1)*(mid+1) > x) { return mid; } if(mid*mid < x) start = mid+1; else end = mid-1; } return 0; }};
public class Solution { public int mySqrt(int x) {if (x <= 1) {return x == 1 ? 1 : 0;}long i = 1, j = x >> 1;while (i <= j) {long m = (i + j) >> 1;long mm = m * m;if (mm <= x && mm + m + m + 1 > x) {return (int)m;} else if (mm > x) {j = m - 1;} else {i = m + 1;}}return (int)i; }}
0 0
- LeetCode: Sqrt(x)
- LeetCode sqrt(x)
- [Leetcode] Sqrt(x)
- LeetCode :Sqrt(x)
- leetcode 53: Sqrt(x)
- [LeetCode] Sqrt(x)
- Leetcode 69 sqrt(x)
- [Leetcode] Sqrt(x)
- leetcode:Sqrt(x)
- 【leetcode】sqrt(int x)
- [LeetCode]Sqrt(x)
- [leetcode]Sqrt(x)
- LeetCode-Sqrt(x)
- [leetcode] Sqrt(x)
- [leetcode] Sqrt(x)
- LeetCode - Sqrt(x)
- leetcode之sqrt(x)
- LeetCode | Sqrt(x)
- Block
- spring 初始化ApplicationContext的几种方式
- 基于Processing的人物八方向移动(加入图片)演示:X,Y,XY同时到达移动
- Solr之中文分词
- 关于动态数组的愚见
- [leetcode] Sqrt(x)
- mac配置环境变量
- datagridview复制粘贴行与单元格内容
- Pascal's Triangle
- Android Studio 三种添加插件的方式
- Install Subversion 1.8.9 ( SVN Client ) on CentOS/RHEL
- LeetCode Triangle
- Android Log 跟踪
- 怎么清除Android开发中的垃圾代码?