Skip to content

Commit ba0309e

Browse files
Leetcode 50
1 parent 9ede68f commit ba0309e

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

Leetcode/Leetcode_50.py

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

0 commit comments

Comments
 (0)