Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def getPermutation(self, n: int, k: int) -> str:
- self.count = 0
- def render_permutations(nums):
- if not len(nums):
- self.count += 1
- if self.count == k:
- self.found_ans = True
- return ""
- for index in range(len(nums)):
- res = str(nums[index]) + render_permutations(nums[:index] + nums[index+1:])
- if self.found_ans:
- return res
- res = ""
- return res
- self.found_ans = False
- nums = [i for i in range(1, n+1)]
- res = render_permutations(nums)
- return res
Advertisement
Add Comment
Please, Sign In to add comment