Skip to content

Commit 7638390

Browse files
authored
leetcode( 50. Pow(x, n))
1 parent 6832cdc commit 7638390

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

problem41/main.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
3+
class Solution {
4+
double myPow(double x, int n) {
5+
6+
double _inside(double x,int n){
7+
8+
if(x==0) return 0;
9+
if(n==0) return 1;
10+
11+
12+
double result=_inside(x*x,(n/2).toInt());
13+
14+
return n.isEven?result:x*result;
15+
}
16+
17+
return _inside(n.isNegative?1/x:x,n);
18+
}
19+
}

0 commit comments

Comments
 (0)