Subsets

 

78. Subsets

Solution

  1. For each subsets up to i-1, append nums[i] to the end of it to find subsets up to i.
    def subsets(self, nums):
     """
     :type nums: List[int]
     :rtype: List[List[int]]
     """
     result = [[]]
     for num in nums:
         result += [i + [num] for i in result]
     return result