LeetCode-Pow(x, n)
来源:互联网 发布:古墓丽影 mac 编辑:程序博客网 时间:2024/06/15 08:44
Recursive:
public class Solution { public double pow(double x, int n) { if ( n == 0 ) return 1; double half = pow ( x, n/2); double res = 1.0; if ( n % 2 == 0 ){ res = half * half; } else if ( n > 0) res = half * half * x; else res = half * half / x; return res; }}
Iterative:
public class Solution { public double pow(double x, int n) { if ( n == 0 ) return 1; double res = 1.0; for ( int i = n; i != 0; i/=2 ){ if ( i % 2 != 0 ) res *= x; x *= x; } if ( n < 0 ) res = 1.0/res; return res; }}
0 0
- 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)
- 【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
- 【leetcode】Pow(x, n)
- 【Leetcode】Pow(x, n)
- LeetCode Pow(x, n)
- Leetcode: Pow(x, n)
- hello world
- signed和unsigned之间
- Java写的爬虫爬百度首页Code《转自零基础写Java知乎爬虫之先拿百度首页练练手》
- POJ 3368 Frequent values(RMQ)
- 点云txt文件—>pcd文件
- LeetCode-Pow(x, n)
- JavaScript对象引用
- js for循环 setTimeout与setInterval测试
- 【黑马程序员】---Objective-C面向对象知识总结
- boost asio编程笔记
- 安卓的动画效果
- 参数 sync_binlog、innodb_support_xa、innodb_flush_log_at_trx_commit
- 阿里巴巴安全部道哥、云舒3月10日在北邮讲座小记
- Pow(x, n)