6-Lines python solution from left position to right position

  • 0
    class Solution(object):
    def getPermutation(self, n, k):
        res, now='', [i for i in xrange(1,n+1)]
        for i in xrange(n-1,-1,-1):
            index, k=(k-1)/math.factorial(i), k%math.factorial(i)
            del now[index]
        return res

Log in to reply

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