题目
Number: 50
Difficulty: Medium
Tags: Math Binary Search
Implement pow(x, n).
题解
实现幂函数。
代码
double myPow(double x, int n) {
if( x == 1 || n == 0)
return 1;
double t = myPow(x, n / 2);
if(n % 2)
return n < 0 ? 1 / x * t * t : x * t * t;
else
return t * t;
}