LeetCode第50.之Pow(x, n)
来源:互联网 发布:开源 数据上报 编辑:程序博客网 时间:2024/06/08 02:49
运用递归解,另外注意n的各种取值的情况。
C++代码:
#include <iostream>#include <limits>using namespace std;class Solution {public: double myPow(double x, int n) { if (0 == n) return 1; else if (n < 0) { //INT_MIN的绝对值比INT_MAX大一 if (INT_MIN == n) { return 1/(myPow(x, INT_MAX)*x); } return 1/myPow(x, -n); } else { double temp= myPow(x, n>>1); if (0 == n%2) { return temp*temp; } else return temp*temp*x; } }};int main(){ Solution s; cout<<s.myPow(0.3, 3); cout<<endl; return 0;}
0 0
- LeetCode第50.之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]50.Pow(x, n)
- LeetCode --- 50. Pow(x, n)
- [Leetcode] 50. Pow(x, n)
- [leetcode] 50.Pow(x, n)
- LeetCode 50. Pow(x, n)
- 50. Pow(x, n) LeetCode
- [leetcode] 50. Pow(x, n)
- Leetcode 50. Pow(x, n)
- [LeetCode]50. Pow(x, n)
- LeetCode *** 50. Pow(x, n)
- [随记]浅谈pdfobject.js实现网页PDF文件浏览
- MyBatis Generator生成sqlMap、DAO、mo
- 想赚大钱,就别太着急!
- 结束了——开始了
- Web_PHP_Curl浅说;
- LeetCode第50.之Pow(x, n)
- android studio 预览时 com/android/util/PropertiesMap
- [安卓初学者实验]使用计时器(Chronometer)实现可暂停的计时器
- 主流开源框架(比如:Xutils)中使用注解的原理
- Ionic安装配置教程
- 1008. Elevator (20)
- 实习杂记(25):MarginStart和MarginLeft
- Java千百问_01基本概念(014)_同步、异步有什么区别
- PCLint error 1566 解决方法