题目:
题解:
class Solution:def getPermutation(self, n: int, k: int) -> str:factorial = [1]for i in range(1, n):factorial.append(factorial[-1] * i)k -= 1ans = list()valid = [1] * (n + 1)for i in range(1, n + 1):order = k // factorial[n - i] + 1for j in range(1, n + 1):order -= valid[j]if order == 0:ans.append(str(j))valid[j] = 0breakk %= factorial[n - i]return "".join(ans)