快速幂
注意int范围为$[2^{31},2^{31} - 1]$,若n为最小值,变为正数时会溢出,所以先用longlong存n比较好
class Solution { public: double myPow(double x, int n) { int flag = 0; long long N = (long long)n; if (N < 0) flag = 1, N = -N; double ret = 1; while(N) { if(N & 1) ret *= x; x = x * x; N >>= 1; } return flag ? 1 / ret : ret; } };