leetcode快速幂—— 50. Pow(x, n)
来源:互联网 发布:php采集器 代码 编辑:程序博客网 时间:2024/05/22 22:10
class Solution { public double myPow(double x, int n) { int flag = n >= 0 ? 1 : -1; double res = quickPow(x, Math.abs(n)); if(flag == 1) return res; else return 1.0 / res; } public double quickPow(double x, int n) { if(n==0) return 1; int k = n / 2; double res = quickPow(x, n/2); if(k*2 == n) { return res * res; } else { return res * res * x; } } public static void main(String[] args) { Solution solution = new Solution(); System.out.println(solution.myPow(2, -1)); }}
阅读全文
0 0
- leetcode快速幂—— 50. 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 —— Pow(x, n)
- LeetCode——Pow(x, n)
- leetcode 050 —— 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)
- JavaGC
- java常用api总结
- TextRank算法
- Android 一个app启动另一个app
- Oracle 11gR2 Client 客户端安装步骤(图文详解)
- leetcode快速幂—— 50. Pow(x, n)
- jquery动态新增的元素无法触发事件问题的解决办法方法
- android studio 打包时xml文件中 string 没有翻译的解决办法
- iOS-制作.a静态库SDK和使用.a静态库
- IntelliJ IDEA使用教程(很全)
- UeLogViewer的安装步骤
- git命令基础(一)
- (转)如何而去掉android中Button自带的阴影效果
- 文章标题 Asp.net中 Directory.Delete(path,ture)会导致Session["User"]==null