Skip to content

Commit c9093ad

Browse files
authored
Create 50-Pow(x, n)
1 parent bbcff29 commit c9093ad

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

50-Pow(x, n)

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def myPow(self, x: float, n: int) -> float:
3+
def helper(x, n):
4+
if x == 0: return 0
5+
if n == 0: return 1
6+
7+
res = helper(x * x, n // 2)
8+
return x * res if n % 2 else res
9+
10+
res = helper(x, abs(n))
11+
return res if n >= 0 else 1 / res

0 commit comments

Comments
 (0)