Advertisement
nikunjsoni

50

May 14th, 2021
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     double myPow(double x, int n) {
  4.         double res = 1.0;
  5.         while(n){
  6.             if(n&1) {
  7.                 if(n > 0)
  8.                     res = res*x;
  9.                 else
  10.                     res /= x;
  11.             }
  12.             x = x*x;
  13.             n /= 2;
  14.         }
  15.         return res;
  16.     }
  17. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement