Problem Description
[https://leetcode.com/problems/powx-n/]
Implement pow(x, n).
思路
不明白这种题为什么会是mid的。。。
Code
package q050;
public class Solution {
public double myPow(double x, int n) {
if (n == 0)
return 1;
if(n<0){
x=1/x;
n=-n;
}
if (n % 2 == 0) {
return myPow(x * x, n / 2);
} else {
return myPow(x, n - 1) * x;
}
}
}