One Line Python Solution (DFS/BackTracking)


  • 0
    J

    For a list of numbers, each time I pick one of these numbers as the target number, and recursively doing this for the rest list of numbers.

    class Solution(object):
        def permute(self, nums):
            """
            :type nums: List[int]
            :rtype: List[List[int]]
            """
            return [[nums[i]]+s for i in range(len(nums)) for s in self.permute(nums[0:i]+nums[i+1:])] or [nums[0:]]
    

Log in to reply
 

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