Share my easy to understand AC recursive python solution (52 ms, 83.84%)


  • -1
    E
    class Solution(object):
        def subsets(self, nums):
    
            if not nums:
                return [[]]
            head, tail = nums[0], nums[1:]
            
            smaller = self.subsets(tail)
            
            ret = []
            for item in smaller:
                ret.append(item)
                ret.append( sorted(item + [head]))
            return ret

Log in to reply
 

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