Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- double helper(double x, long long int n){
- if(n==0)return 1;
- if(n%2==0){
- double k = helper(x,n/2);
- return k*k;
- }
- return x*helper(x,n-1);
- }
- double myPow(double x, long long int n) {
- int flag = 0;
- if(n<0){
- flag = 1;
- n = -1*n; //n = abs(n);
- }
- double ans = helper(x,n);
- if(flag==1){
- return 1/ans;
- }
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement