알고리즘 - 부분 집합
모든 부분 집합을 리턴하라.
Input | Output |
---|---|
nums = [1,2,3] | [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]] |
Solution (트리의 모든 DFS 결과)
class Solution:
def subsets(self, nums: List[int]) -> List[List[int]]:
result = []
def dfs(index, path):
result.append(path)
for i in range(index, len(nums)):
dfs(i + 1, path + [nums[i]])
dfs(0, [])
return result
댓글남기기