We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4be3ea4 commit cf4f478Copy full SHA for cf4f478
Permutation Sequence/Permutation_Sequence.py
@@ -0,0 +1,27 @@
1
+# 按位确定
2
+# 40ms 84.01%
3
+class Solution:
4
+ def getPermutation(self, n, k):
5
+ """
6
+ :type n: int
7
+ :type k: int
8
+ :rtype: str
9
10
+ def factorial(num):
11
+ if num is 0:
12
+ return 1
13
+ else:
14
+ return num * factorial(num - 1)
15
+
16
+ res_list = ''
17
+ temp_list = list(range(1, n + 1))
18
+ k -= 1
19
20
+ while n > 0:
21
+ temp = factorial(n - 1)
22
+ res_list += str(temp_list[k // temp])
23
+ del temp_list[k // temp]
24
+ k = k - k // temp * temp
25
+ n -= 1
26
27
+ return res_list
0 commit comments