Python short solution

  • 0
    class Solution(object):
        def getPermutation(self, n, k):
            r = ''; fac = [1]*(n+1); s = []
            for i in xrange(1, n+1):
                fac[i] = i*fac[i-1]
            for i in xrange(n, 0, -1):
                ind = (k-1)/fac[i-1]
                r += str(s[ind])
                del s[ind]
                k %= fac[i-1]
            return r

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.