题目描述:
Implement pow(x, n).
代码:
double solution::pow(double x,int n) { if(n == 0) return 1; if(n == 1) return x; if(n < 0) { n = n * -1; x = 1 / x; } return n%2==0?pow(x*x,n/2):x*pow(x*x,n/2); }
原文地址:http://blog.csdn.net/yao_wust/article/details/42490427