[LeetCode] Pow(x, n) 解题报告
来源:互联网 发布:大汉主义知乎 编辑:程序博客网 时间:2024/06/04 23:19
Implement pow(x, n).
» Solve this problem
[解题思路]
二分法,注意n<0的情况。
[Code]
1: double power(double x, int n)
2: {
3: if (n == 0)
4: return 1;
5: double v = power(x, n / 2);
6: if (n % 2 == 0)
7: return v * v;
8: else
9: return v * v * x;
10: }
11: double pow(double x, int n) {
12: // Start typing your C/C++ solution below
13: // DO NOT write int main() function
14: if (n < 0)
15: return 1.0 / power(x, -n);
16: else
17: return power(x, n);
18: }
0 0
- Leetcode Pow(x, n) 解题报告
- LeetCode-Pow(x, n)-解题报告
- [LeetCode] Pow(x, n) 解题报告
- [leetcode] 50. Pow(x, n) 解题报告
- [Leetcode] 50. Pow(x, n) 解题报告
- [LeetCode]pow(double x,int n)解题报告
- Leetcode #50. Pow(x, n) 幂实现 解题报告
- [leetcode]50. Pow(x, n)@Java解题报告
- 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] Permutations II 解题报告
- [LeetCode] Plus One 解题报告
- [LeetCode] Populating Next Right Pointers in Each Node 解题报告
- [LeetCode] Populating Next Right Pointers in Each Node II 解题报告
- [LeetCode] Recover Binary Search Tree 解题报告
- [LeetCode] Pow(x, n) 解题报告
- [LeetCode] Remove Duplicates from Sorted Array 解题报告
- ANSYS SpaceClaim 2015中文免费版
- [LeetCode] Remove Duplicates from Sorted Array II 解题报告
- [LeetCode] Remove Duplicates from Sorted List 解题报告
- [LeetCode] Remove Element 解题报告
- [LeetCode] Remove Nth Node From End of List 解题报告
- [LeetCode] Restore IP Addresses 解题报告
- [LeetCode] Reverse Integer 解题报告