classSolution: defgetPermutation(self, n, k): """ :type n: int :type k: int :rtype: str """ # 6 star. 必须掌握
k -= 1 fact = 1 for i in range(1, n): fact *= i rs = "" nums = list(range(1, 10)) for i in range(n-1, -1, -1): index = k // fact num = nums.pop(index) rs += str(num) if i > 0: k %= fact fact //= i return rs