Skip to content

Commit 279f90d

Browse files
committedMay 10, 2020
2020-05-10
1 parent e6972d3 commit 279f90d

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed
 

‎0050.Pow(x,n)/0050-Pow(x,n).py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
11
class Solution(object):
2-
def myPow(self, x0, n):
2+
def myPow(self, x, n):
33
"""
44
:type x: float
55
:type n: int
66
:rtype: float
77
"""
8-
if not n:
9-
return 1
10-
def helper(x, n, tmp):
11-
print n, x
12-
if n <= 1:
13-
return x * tmp
14-
if n % 2:
15-
tmp *= x
16-
n -= 1
17-
return helper(x * x, n // 2, tmp)
18-
op = 1
19-
if n < 0:
20-
op = -1
21-
res = helper(x0, abs(n), 1)
22-
return res if op > 0 else 1.0/res
8+
return x ** n

0 commit comments

Comments
 (0)
Please sign in to comment.