My python backtracking solution


  • 2
    G
    enter code hereclass Solution(object):
    def permute(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        res=[]
        max=len(nums)
        self.helper(res,[],nums,0,max)
        return res
        
    def helper(self,res,l,r,n,max):
        if n==max:
            res.append(l)
        for i in range(0,len(r)):
            self.helper(res,l+[r[i]],r[:i]+r[i+1:],n+1,max)

Log in to reply
 

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