50. Pow(x, n) (INT; Divide-and-Conquer)

时间:2022-06-05 18:13:12

Implement pow(x, n).

思路:二分法,将每次相乘,转化成平方。

class Solution {
public:
double myPow(double x, int n) {
if(n==) {
return ;
} double result = myPow(x, n/);
result*= result;
if(n%==) result = x * result;
else if(n%==-) result = (/x) * result; //negative number
return result;
}
};