69. Sqrt(x)
来源:互联网 发布:java 定时 编辑:程序博客网 时间:2024/06/03 19:09
原文题目:
Implement int sqrt(int x)
.
Compute and return the square root of x.
读题:题目就是求x的开根号,很重要的一点是返回值是整数,而不是浮点数,因此这个开根号其实只是接近实际开根号的值的整数而已,并不是精确的开根号,因此可以采用二分法进行处理。
class Solution(object): def mySqrt(self, x): """ :type x: int :rtype: int """ if not x: return 0 start = 1 end = x//2 + 1 #取中间值,且为整数 while start <= end: mid = int((start+end)/2) if mid**2 == x: return mid elif mid**2 >x: end = mid - 1 else: start = mid + 1 return end
阅读全文
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)
- regular-expression-matching
- 16位汇编第九讲汇编指令以及逆向中的花指令
- 【转】React Native签名打包生成Android apk
- 解决“只能通过Chrome网上应用商店安装该程序”的方法
- JAVA-IDEA-配置
- 69. Sqrt(x)
- 一致性哈希算法
- 服务器请求的优化和性能的监控
- 可以一读
- 曳光弹 曳光代码 原型制作 读《读程序员修炼之道》
- Kontlin边用边学
- nginx 负载均衡时,一台tomcat宕机时的问题 自动切换
- 编程的时候最头疼的事:命名
- Linux 环境下调用C++库ocilib操作Oracle数据