LeetCode OJ Pow(x, n)
来源:互联网 发布:捡宝贝淘宝u站 编辑:程序博客网 时间:2024/06/07 01:58
Implement pow(x, n).
calculate the pow of a double, use fast power and notice that the exponent may be negative.
class Solution {public: double pow(double x, int n) { if (n < 0) { // for negative n x = 1 / x; n = -n; } if (n == 1) return x; // when n = 1 in recursion, return itself if (n == 0) return 1.0; // n^0 = 1(n != 0) /* fast power */ if (n & 1 == 1) { return x * pow(x, n - 1); } else { double temp = pow(x, n / 2); return temp * temp; } }};
0 0
- LeetCode OJ:Pow(x, n)
- [LeetCode OJ]Pow(x, n)
- LeetCode OJ Pow(x, n)
- <LeetCode OJ> 50. Pow(x, n)
- LeetCode OJ 50. Pow(x, n)
- LeetCode OJ 之 Pow(x, n) (求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)
- LeetCode OJ Reverse Integer
- COJ--1541: There is No Alternative
- boost xpressive简明用法
- SVN与TortoiseSVN实战:冲突详解(二)
- JAVA创建单例的5中常见方式及比较
- LeetCode OJ Pow(x, n)
- jdbC连接到数据库
- LeetCode OJ Merge k Sorted Lists
- mybatis报错java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long
- UVa 10375 - Choose and divide
- 显隐转换,虚成员和抽象成员
- LeetCode OJ Remove Nth Node From End of List
- IOS7(新UI之自定义UITableViewCell)
- LeetCode OJ Rotate List