[LeetCode 50]Pow(x, n)

题目链接:powx-n

/** * Implement pow(x, n). * */public class PowXN {//299 / 299 test cases passed.//Status: Accepted//Runtime: 343 ms//Submitted: 0 minutes agostatic double pow(double x, int n) {if(n < 0) {return 1.0 / power(x, -n);}else {return power(x, n);}}//绝壁得分治法,,不然得超时或溢出static double power(double x, int n) {if(n == 0) return 1;double half = power(x, n / 2);if(n % 2 != 0) {return x * half * half;} else {return half *half;}}public static void main(String[] args) {System.out.println(pow(0.00001, 2147483647));}}

自己要先看得起自己,别人才会看得起你

[LeetCode 50]Pow(x, n)

相关文章:

你感兴趣的文章:

标签云: