leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0050.cpp (237B)


      1 class Solution {
      2   public:
      3     double myPow(double x, int n) {
      4         if (n == 0) return 1;
      5         if (n < 0) return 1 / x * myPow(1 / x, -(n + 1));
      6         return (n % 2 == 0) ? myPow(x * x, n / 2) : x * myPow(x * x, n / 2);
      7     }
      8 };