Skip to content

Commit a00e23d

Browse files
committed
feat: powx-n
1 parent 1fe0738 commit a00e23d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

divide.powx-n.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def myPow(self, x: float, n: int) -> float:
3+
return self.mul(x, n) if n >=0 else 1.0 / self.mul(x, -n)
4+
5+
def mul(self, x, n):
6+
if n == 0:
7+
return 1
8+
y = self.mul(x, n // 2)
9+
return y * y if n % 2 == 0 else y * y * x
10+
11+
so = Solution()
12+
print(so.myPow(2, 3))
13+
print(1//2)

0 commit comments

Comments
 (0)