We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9911aa6 commit 8987d57Copy full SHA for 8987d57
0050-powx-n/0050-powx-n.java
@@ -0,0 +1,31 @@
1
+class Solution {
2
+ public double myPow(double x, int n) {
3
+ double result=1;
4
+ long temp=n;
5
+ if(temp<0) temp=-1*n;
6
+ while(temp>0){
7
+ if(temp%2==0){
8
+ x=x*x;
9
+ temp=temp/2;
10
+ }
11
+ else{
12
+ result=result*x;
13
+ temp=temp-1;
14
15
16
+
17
+ if(n<0) result=1/result;
18
+ if(n==Integer.MIN_VALUE){
19
+ if(x>1){
20
+ result=0;
21
22
23
24
+ result=1;
25
26
27
28
29
+ return result;
30
31
+}
0 commit comments