Python using backtracking, simple and easy


  • 0
    K
    class Solution(object):
        def subsets(self,nums):
            res = []    
            self.dfs(nums,0,[],res,len(nums))
            return res
        def dfs(self,nums,index,path,res,l):       
            res.append(path)
            for i in xrange(index,len(nums)):
                self.dfs(nums,i+1,path+[nums[i]],res,l)
    

Log in to reply
 

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