leetcode force buckle 78. subset

Given a set of no repeating element integer array nums, which returns an array of all possible subsets (power set).

Description: Solution Set can not contain duplicate subsets.

Example:

Input: nums = [1,2,3]
Output:
[
  [3],
  [1],
  [2],
  [2,3],
  [1,3],
  [2,3],
  [1,2 ],
  []
]

An iterator is obtained, where combinations nums is obtained in the i-th combined data, and permutations are arranged to give

class Solution(object):
    def subsets(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        result = []
        for i in range(len(nums)+1):
            for j in itertools.combinations(nums, i):
                result.append(j)
        return result

 

Published 302 original articles · won praise 161 · views 490 000 +

Guess you like

Origin blog.csdn.net/qq_32146369/article/details/104112439