Python concise recursive solution (one line)


  • 0
    W
    class Solution(object):
        def subsets(self, nums):
            """
            :type nums: List[int]
            :rtype: List[List[int]]
            """ 
            return [[n]+r for i,n in enumerate(nums) for r in self.subsets(nums[i+1:])]+[[]]
    

Log in to reply
 

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