We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9201868 commit 8b1d38eCopy full SHA for 8b1d38e
βsolution/0050.Pow(x, n)/Solution.py
@@ -0,0 +1,21 @@
1
+class Solution:
2
+ def myPow(self, x: float, n: int) -> float:
3
+
4
+ """
5
+ :type x: float
6
+ :type n: int
7
+ :rtype: float
8
9
10
+ answer = 1
11
+ if x == 1 or n == 0:
12
+ return 1
13
+ if x == -1:
14
+ return 1 if n%2 == 0 else -1
15
16
+ for i in range(abs(n)):
17
+ answer *= x
18
+ if (abs(answer) < 10 ** -5 and n > 0) or (abs(answer) > 10 ** 5 and n < 0):
19
+ return 0
20
21
+ return answer if n > 0 else 1/answer
βsolution/README.md
@@ -249,6 +249,7 @@
249
βββ 0050.Pow(x, n)
250
βΒ Β βββ Solution.java
251
βΒ Β βββ Solution.js
252
+βΒ Β βββ Solution.py
253
βββ 0051.N-Queens
254
βΒ Β βββ Solution.java
255
βββ 0052.N-Queens II
0 commit comments