Skip to content

Commit cf4f478

Browse files
Add files via upload
1 parent 4be3ea4 commit cf4f478

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)