[leetcode] Implement pow(x, n). Subscribe to see which companies asked this question
2016-09-03 07:32
381 查看
Implement pow(x, n).
要注意n<0的情况。
要注意n<0的情况。
class Solution { public: double myPow(double x, int n) { if(n<0) return 1/power(x,-n); else return power(x,n); } double power(double x, int n){ double res; if(n==0) return 1; double half = power(x,n/2); if(n%2==0) return half*half; else return x*half*half; } };
相关文章推荐
- LeetCode: Implement pow(x, n).
- LeetCode Implement pow(x, n).
- leetCode---Implement pow(x, n)
- 【LeetCode-面试算法经典-Java实现】【050-Implement pow(x, n)(求x的n次方)】
- leetcode 50 Implement Pow(x, n)
- leetcode------Implement pow(x, n).
- 【LEETCODE】232-Implement Queue using Stacks
- LeetCode-Implement Trie (Prefix Tree) (C++)
- leetcode:数学:spuer pow(372)
- leetcode 225 & 232.Implement Stack using Queues & Implement Queue using Stacks
- Leetcode练习- Pow(x,n)
- https://leetcode.com/problems/powx-n/
- LeetCode(36)- Implement Stack using Queues
- LeetCode3.2(Implement strStr())
- LeetCode 28 Implement strStr()
- [LeetCode] Pow(x, n)
- LeetCode 28:Implement strStr()
- leetcode 之Implement strStr()(27)
- Leetcode题解:Pow(x, n)
- Leetcode 28 Implement strStr()