[LeetCode] Pow(x, n) 解题报告
2016-01-12 11:07
477 查看
Implement pow(x[/i], n[/i]).
» Solve this problem
[解题思路]
二分法,注意n<0的情况。
» 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: }
相关文章推荐
- [LeetCode] Remove Duplicates from Sorted Array 解题报告
- [LeetCode] Remove Duplicates from Sorted Array II 解题报告
- [LeetCode] Remove Duplicates from Sorted List 解题报告
- [LeetCode] Remove Element 解题报告
- Attribute is missing the Android namespace prefix(属性是失踪的Android名称空间前缀)
- Codeforces Round #309 (Div. 2) C
- JavaScript正则表达式
- kohana安装总结
- vs2005中microsoft ado data control 6.0控件问题
- AC自动机 LA 4670 Dominating Patterns
- pt-table-checksum 针对某个库做数据校验
- 什么是可重入锁
- LeetCode:Isomorphic Strings
- Ubuntu下MySql配置
- [Leetcode] Distinct Subsequences 解题报告
- [LeetCode] Divide Two Integers 解题报告
- [LeetCode] Edit Distance 解题报告
- [LeetCode] First Missing Positive 解题报告
- [LeetCode] Flatten Binary Tree to Linked List 解题报告
- [LeetCode] Generate Parentheses 解题报告