aboutsummaryrefslogtreecommitdiff
path: root/pow_xn.cpp
blob: f64161f3df724e9787d572405f7a3c342b16315d (plain)
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() {}