L LeetCode 2016-08-09 LeetCode 50: Pow(x, n) LeetCode Math Implement pow(x, n). 代码1234567891011121314151617181920212223242526double myPow(double x, int n) { double res = 1; double flag = x; int m = n; if (n < 0) { x = 1 / x; if (n == INT_MIN) { n = INT_MAX; } else { n = -n; } } while (n>0) { if (n & 1 == 1) { res = res*x; } x *= x; n = n >> 1; } if (m == INT_MIN) { if (flag < 0) { return -res; } } return res;} 下一篇 LeetCode 69: Sqrt(x) 上一篇 LeetCode 7: Reverse integer