Skip to content

Commit df3e5f4

Browse files
committed
Solved leetcode 50
1 parent 3799311 commit df3e5f4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

50/50.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution:
2+
def myPow(self, x: float, n: int) -> float:
3+
def helper(x, n):
4+
if(x == 0):
5+
return 0
6+
elif(n == 0):
7+
return 1
8+
else:
9+
newExp = n // 2
10+
partPow = helper(x, newExp)
11+
refactor = n - 2*newExp
12+
return partPow * partPow * (x**refactor)
13+
14+
if(n < 0):
15+
return 1/helper(x, abs(n))
16+
else:
17+
return helper(x, abs(n))
18+
19+
20+

0 commit comments

Comments
 (0)