问道面试题:实现pow(double x, int n)
leetcode上的题目,下面是我代码
class Solution {
public:
double pow(double x, int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(n == 0)
return 1;
if(x == 0)
return 0;
if(n > 0)
return x*pow(x, n - 1);
if(n < 0)
return 1 / pow(x, -n);
}
};