Pow(x, n)
来源:互联网 发布:mac os x dmg vmware 编辑:程序博客网 时间:2024/05/19 21:41
参考:http://blog.csdn.net/linhuanmars/article/details/20092829
参考了这上面的二分解法。自己写了一个最简单的发现会超时报错。
关于递归方面一直不是很好,这学期要加强下算法这方面的知识。 关于代码中的几种情况用三个例子进行说明。
代码:
package codes;public class Pow {public static void main(String[] args) { System.out.println(new Pow().myPow(3, 3)); System.out.println(-5%2);}public double myPow(double x, int n) { //要考虑 n 为负数的情况if(n == 0) return 1.0; double half = myPow(x,n/2);if(n%2 ==0){ return half * half; }else if(n>0){ return half * half * x; }else return <span style="font-family: Arial, Helvetica, sans-serif;">half * half /x ;</span> }}
0 0
- Pow(x, n) / Super Pow
- LeetCode: Pow(x, n)
- LeetCode Pow(x,n)
- [Leetcode] Pow(x, n)
- LeetCode: Pow(x, n)
- Leetcode: Pow(x,n)
- [LeetCode] Pow(x, n)
- [Leetcode] Pow(x,n)
- Pow(x, n)
- 【leetcode】Pow(x, n)
- Pow(x, n)
- 求 pow(x, n)
- [LeetCode]Pow(x, n)
- Pow(x,n)
- Pow(x, n)
- Pow(x, n)
- [leetcode]Pow(x, n)
- LeetCode-Pow(x, n)
- 分享营销型网站SEO优化心得和技巧
- union和union all的区别
- LightOJ 1072 - Calm Down 【二分】
- MongoDB使用总结(C#版 潘鹏)
- 可以替代Ghost的系统备份/恢复利器Clonezilla
- Pow(x, n)
- oracle登陆命令
- ubuntu git 服务器搭建
- 升级WIN10后80端口被占用
- oracle登陆账户信息
- Oracle 权限 管理大全
- IIS7.5安全配置研究
- WingIDE破解 python2.x和python3.x
- fragment懒加载