Skip to content

Commit

Permalink
Merge pull request #96 from kajurampatell/patch-5
Browse files Browse the repository at this point in the history
find power of x , n times
  • Loading branch information
avastino7 authored Nov 1, 2022
2 parents f6ab578 + e79845f commit f773537
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions myPow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class Solution {
public double myPow(double x, int n) {



double temp=1,flag=1;
if(n>=0){
while(n>0){
if(n%2!=0){
temp=temp*x;
n--;
}
x=x*x;
n=n/2;
}
return temp;
}
else{
n=-n;
while(n>0){
if(n%2!=0){
temp=temp*(1/x);

n--;
}
x=x*x;
n=n/2;
}
return temp;
}

}
}

0 comments on commit f773537

Please sign in to comment.