python concise solution


  • 0
    R
    class Solution(object):
        def getPermutation(self, n, k):
            """
            :type n: int
            :type k: int
            :rtype: str
            """
            nums = [str(_) for _ in range(1,n+1)]
            k -= 1
            ans = ""
            for i in range(n)[::-1]:
                ans += nums.pop(k / math.factorial(i))
                k %= math.factorial(i)
            return ans
    

Log in to reply
 

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