LeetCode---50. Pow(x, n)(指数运算x的n次方)
来源:互联网 发布:gta5妹子捏脸数据 编辑:程序博客网 时间:2024/04/29 23:43
Implement pow(x, n).
Subscribe to see which companies asked this question
//思路:主要考察越界,n为负数等问题
方法一:API
public class Solution { public double myPow(double x, int n) { // double Math.pow(double ,double) if(x==0){return 0;} if(n==1){return x;} double result=Math.pow(x,n); return result; }}方法二://考虑 n=负数边界
public class Solution { public double pow(double x, int n) { if (n == 0) { return 1; } if (n == 1) { return x; } boolean isNegative = false; if (n < 0) { isNegative = true; n *= -1; } int k = n / 2; int l = n - k * 2; double t1 = pow(x, k); double t2 = pow(x, l); if (isNegative) { return 1/(t1*t1*t2); } else { return t1*t1*t2; } }}
0 0
- LeetCode---50. Pow(x, n)(指数运算x的n次方)
- LeetCode 50. Pow(x, n) x的n的次方
- Pow(x, n) 指数 @LeetCode
- Pow(x,n) x的n次方
- leetCode 50.Pow(x, n) (x的n次方) 解题思路和方法
- [LeetCode-50] Pow(x, n)(数值的整数次方)
- 50. Pow(x, n) 求指数
- leetcode:Pow(x, n) (计算x的n次方) 【面试算法题】
- Leetcode 50 Pow(x,n) (求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)
- Linux重定向及标准输入、输出、错误相关
- OC三大特性之封装
- 三圈问题的解决
- C#中AppDomain.CurrentDomain.BaseDirectory及各种路径获取方法
- Android练习-----自动完成文本框(AutoCompleteTextView)(搜索框)
- LeetCode---50. Pow(x, n)(指数运算x的n次方)
- CGI、FastCGI、PHP-CGI与PHP-FPM
- Hadoop0.20.2 完全分布式安装和配置
- 习题4-1 象棋 uva1589
- 你真的懂select模型吗?
- Java Spring MVC 入门- HelloWord+配置IntelliJ idea的Tomcat服务器
- Pycharm中设置断点调试DJango
- 同步令牌模式防范CSRF跨站请求伪造攻击
- Android学习路线