69. Sqrt(x)
来源:互联网 发布:mac 黑客帝国屏保 编辑:程序博客网 时间:2024/06/15 12:33
1.二分法解题,最恶心的就是边界问题,为了边界问题基本上都得调试一段时间
注意,当 x 为 int 时,相乘会越界(大于int的最大数2147483647) ,所以用 相除 代替 相乘
public class Solution { public int mySqrt(int x) { if(x<=1) return x; int left = 1; int right = x; int mid = 0; while(left <=right){ mid = (left + right) / 2; if(mid == (x / mid)) return mid; if(mid < (x / mid)){ left = mid + 1; }else{ right = mid - 1; } } return right; } }
阅读全文
0 0
- LeetCode 69. Sqrt(x)
- LeetCode 69.Sqrt(x)
- LeetCode --- 69. Sqrt(x)
- [Leetcode] 69. Sqrt(x)
- [leetcode] 69.Sqrt(x)
- 69.Sqrt(x)
- 69. Sqrt(x)
- Leetcode-69.Sqrt(x)
- leetcode--69.sqrt(x)
- 69. Sqrt(x)
- LeetCode 69. Sqrt(x)
- leetcode 69. Sqrt(x)
- 【LeetCode】69. Sqrt(x)
- 69. Sqrt(x) LeetCode
- 69. Sqrt(x)
- 69. Sqrt(x)
- [leetcode] 69. Sqrt(x)
- 69. Sqrt(x)
- MockMVC
- 如何先搜索文件然后在文件中搜索具体内容进行输出?
- js判断一个对象为空对象
- eclipse Maven debug as 启动服务,出现关联不上代码,一闪而过
- linux 启动参数设置 启动打印同时输出到串口和显示器
- 69. Sqrt(x)
- 计算机科学常见工具书清单、项目开发清单
- Jmeter连接SqlServer数据库进行压力测试
- Servlet笔记
- 查找
- Dubbo异步方法调用里的问题
- COJ1911-Card Game
- Java内部类的使用小结
- C++预科——C语言指针回顾(三) 指针的运算