leetcode解题方案--050--pow(x,n)
来源:互联网 发布:jaycn淘宝店是谁开的 编辑:程序博客网 时间:2024/06/05 18:16
题目
Example 1:
Input: 2.00000, 10
Output: 1024.00000
Example 2:
Input: 2.10000, 3
Output: 9.26100
分析
我还以为这道题会考虑精度,然而并没有,
考虑一下算法复杂度就可以啦。
如果要求精度和范围的话,必须要考虑先扩大再缩小
class Solution { public static double myPow(double x, int n) { if (n == 0) { return 1.0f; } if (x == 0) { return 0f; } if (n == 1) { return x; } if (n == -1) { return 1 / x; } double half = myPow(x, n / 2); double ret = half * half; if (n % 2 != 0) { ret = n > 0 ? half * half * x : half * half / x; } else { } return ret; }}
阅读全文
0 0
- leetcode解题方案--050--pow(x,n)
- Leetcode Pow(x, n) 解题报告
- LeetCode-Pow(x, n)-解题报告
- [LeetCode] Pow(x, n) 解题报告
- [leetcode] 50. Pow(x, n) 解题报告
- [Leetcode] 50. Pow(x, n) 解题报告
- LeetCode 050 pow(x,n)
- LeetCode 050 Pow(x, n)
- LeetCode 050 Pow(x, n)
- leetcode 050 Pow(x, n)
- [LeetCode]050-Pow(x,n)
- LeetCode 050 Pow(x, n)
- LeetCode 050 Pow(x,n)
- LeetCode: Pow(x, n)
- LeetCode Pow(x,n)
- [Leetcode] Pow(x, n)
- LeetCode: Pow(x, n)
- Leetcode: Pow(x,n)
- centos用yum安装mongodb及 32位linux(centos)下mongoDB的安装
- 03.创新机遇来源一:意外事件
- haproxy.cfg 配置文件 python脚本管理
- 使用masscan扫描以及相关优化
- 代码健壮性
- leetcode解题方案--050--pow(x,n)
- zz详解数字签名、公匙、私匙、非对称加密
- oracle lower函数和upper函数
- js获取当前日期时间“yyyy-MM-dd HH:MM:SS”
- ANDROID布局实现圆角边框
- SQL Server 浅析存储过程(一)
- 弹力球
- 摘抄(SAP所有模块用户出口(User Exits) )
- 如何正确使用指针?子函数能影响父函数的前提又是什么呢?