https://oj.leetcode.com/problems/powx-n/
二分法
class Solution { public: double pow(double x, int n) { double ans = 1; if(n == 0) return 1.0; if(n == 1) return x; bool isNegative = false; if(n < 0) { isNegative = true; n = -1 * n; } double n1 = n / 2; double n2 = n - n1*2; double t1 = pow(x,n1); //recursively double t2 = pow(x,n2); //recursilvely ans = t1*t1*t2; if(isNegative) ans = 1.0/ans; return ans; } };