leetcode 50 Implement Pow(x, n)
来源:互联网 发布:羽绒服推荐 知乎 编辑:程序博客网 时间:2024/06/05 18:44
Problem: Implement the library function implement Pow(x, n)
Solution: 该博客给出了几种不同的解题思路,值得参考。
http://blog.csdn.net/fengbingyang/article/details/12236121
下面给出其中一种AC 6ms的代码实现
class Solution {public: double myPow(double x, int n) { if (n == 0) return 1.0; else { if (n < 0) { //判断是否溢出 if (n == INT_MIN) return 1.0 / (pow(x, INT_MAX)*x); else return 1.0 / pow(x, -n); }else{ if (n % 2 == 0) { double temp = myPow(x, n >> 1); return temp * temp; } else{ double temp = myPow(x, (n - 1) >> 1); return temp * temp * x; } }//else }//else }};
阅读全文
0 0
- leetcode 50 Implement Pow(x, n)
- leetcode------Implement pow(x, n).
- LeetCode: Implement pow(x, n).
- leetCode---Implement 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)
- leetcode 50 Pow(x, n)
- leetcode || 50、Pow(x, n)
- [leetcode] #50 Pow(x,n)
- LeetCode-50 Pow(x, n)
- Pow(x, n) - LeetCode 50
- Leetcode(50):Pow(x, n)
- LeetCode---(50)Pow(x, n)
- Leetcode #50 Pow(x, n)
- LeetCode(50) Pow(x, n)
- STM8S105系列单片机的PWM输出配置
- 例题 5-3 安迪的第一个字典(Andy's First Dictionary) UVa 10815
- jQuery基础
- PostgreSQL数据库Dig4 ——视图(Views)
- xUtlis网络请求数据之POST
- leetcode 50 Implement Pow(x, n)
- Python返回数组(List)长度的方法
- 浏览器访问tomcat,页面访问出错404,405,500
- 谈谈对Spring IOC的理解
- Qt Windows 7(Win7)下获取并显示电池电量和WIFI信号强度
- HNUST 1522 爱心苹果 (三分思想)
- 如何创建一个VPN连接
- Ubuntu 安装MQTT
- KMP 算法