60 Permutation Sequence
这道题纯考数学,懒得打字解释了 方法如下
from math import factorial class Solution: # @param {integer} n # @param {integer} k # @return {string} def getPermutation(self, n, k): digits = [i for i in range(1,n + 1)] ans = [] k -= 1 while n > 0: ind = k / factorial(n-1) d = digits[ind] ans.append(str(d)) digits.remove(d) k %= factorial(n-1) n -= 1 return "".join(ans)