Search

SubSets

문제 설명 : 제공된 배열의 요소로 만들 수 있는 모든 부분집합을 반환한다.
풀이 방법
백트리킹 방식을 사용하였다. 이를 위해 DFS를 사용하였다.
시간복잡도 : O(2n)O(2^n)
성공 코드
class Solution: def subsets(self, nums: List[int]) -> List[List[int]]: result = [[]] def subsets(current, useable): if not useable: return for i, item in enumerate(useable): result.append(current + [item]) subsets(current + [item], useable[i + 1:]) subsets([], nums) return result
Python
복사