1 line Python, beats 94%


  • 0
    M
    class Solution(object):
        def permute(self, nums):
            return [n[:i] + [nums[0]] + n[i:]
                    for n in self.permute(nums[1:])
                    for i in range(len(n)+1)] if len(nums) > 1 else [nums]
    

Log in to reply
 

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