Algorithm/📊 Problem Solving

[리트코드/Leetcode] 78 - Subsets

posted by sangmin

78 - Subsets

📌 문제

Given an integer array nums of unique elements, return all possible subsets (the power set).

The solution set must not contain duplicate subsets. Return the solution in any order.

📋 코드

from itertools import combinations

class Solution:
    def subsets(self, nums: List[int]) -> List[List[int]]:
        result = []
        for i in range(len(nums)+1):
            comb = list(combinations(nums, i))
            for c in comb:
                result.append(c)

        return result

💡 한마디

반복문을 통해 가능한 조합을 모두 구했다.