1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#include "leetcode.h" class Solution { public: double myPow(double x, int n) { if (n < 0) x = 1 / x; long num = labs(n); double pow = 1; while (num) { if (num & 1) pow *= x; x *= x; num >>= 1; } return pow; } }; int main() {}