forked from Garvit244/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path60.py
More file actions
30 lines (25 loc) · 686 Bytes
/
60.py
File metadata and controls
30 lines (25 loc) · 686 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Solution(object):
def getPermutation(self, n, k):
"""
:type n: int
:type k: int
:rtype: str
"""
nums = []
for index in range(1, n+1):
nums.append(index)
def permute(nums):
if len(nums) == 0:
return []
if len(nums) == 1:
return [nums]
result = []
for index in range(len(nums)):
for p in permute(nums[0:index] + nums[index+1:]):
result.append([nums[index]] + p)
return result
value = permute(nums)[k-1]
result = ""
for val in value:
result += str(val)
return result