Seven line Python Solution by Recursion


  • 0
    Q
    class Solution(object):
        def permute(self, nums):
            """
            :type nums: List[int]
            :rtype: List[List[int]]
            """
            if len(nums) == 1:
                return [nums]
            
            res = []
            for i in range(len(nums)):
                tmp = [[nums[i]]+item for item in self.permute(nums[:i]+nums[i+1:])]
                res.extend(tmp)
            
            return res
    

Log in to reply
 

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