标签:
Implement pow(x, n).
class Solution { public: double pow(double x, int n) { if(n == 0) return 1; return divideConquer(x,n); } double divideConquer(double x, int n) { double result; if(n==1) return x; if(n == -1) return 1/x; if(n%2 == 0) { result = divideConquer(x, n/2); result = result * result; } else { result = divideConquer(x, n/2); if(n>0) result = result * result * x; else result = result * result / x; } return result; } };
50. Pow(x, n) (INT; Divide-and-Conquer)
标签:
原文地址:http://www.cnblogs.com/qionglouyuyu/p/4924796.html