Skip to content

Commit 1dc31b3

Browse files
committed
update some
1 parent 52b8132 commit 1dc31b3

File tree

1 file changed

+14
-0
lines changed
  • solutions/50. Pow(x, n)

1 file changed

+14
-0
lines changed

solutions/50. Pow(x, n) /50.py

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

0 commit comments

Comments
 (0)