LeetCode 50. Pow(x, n)--幂实现
来源:互联网 发布:center os安装windows 编辑:程序博客网 时间:2024/05/17 06:45
Implement pow(x, n).
public class Main {/* public double myPow(double x, int n) {//如果输入是(0.000001,123271483)时间会超时 double sum = 1.0; int absN = Math.abs(n); for (int i = 0; i < absN; i++) { sum = sum * x; } if (n > 0) { return sum; } return 1.0 / sum; }//myPow*/ public double myPow(double x, int m) { double temp = 0; if (m == 0) return 1.0; temp = myPow(x, m / 2); if (m % 2 == 0) { return temp * temp; } else { if (m > 0) return x * temp * temp;//temp >=1,越乘越大 else return (temp * temp) / x;//temp<=1,,越乘越小 } }//myPow public static void main(String[] args) { System.out.println(new Main().myPow(2.0, -3));// System.out.println(new Main().myPow(0.00001, 2147483647));//0 }}300 / 300 test cases passed.
Status: Accepted
Runtime: 19 ms
Your runtime beats 78.95 % of java submissions.
阅读全文
0 0
- 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)
- 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)
- 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)
- Impala高性能探秘之Runtime Filter
- TCP通信过程大讨论
- 简单的浅拷贝和深拷贝
- 电子词典C语言实现
- 森林和二叉树的转化
- LeetCode 50. Pow(x, n)--幂实现
- opencv viz 模块的键盘操作 registerKeyboardCallback
- CodeForces Weakness and Poorness
- 在linux下图形界面和命令行界面的切换
- WEB 集群与负载均衡(一)基本概念
- 信号捕捉
- 598. Range Addition II
- PHP基础教程-17 布尔运算符
- 郑轻 ZZULIOJ 2136: ht的生日party