(LeetCode)78.부분 집합
by hutswing
(LeetCode)78.부분 집합
문제
아이디어
- 트리의 DFS결과 출력
코드
class Solution:
def subsets(self, nums: List[int]) -> List[List[int]]:
result = []
def dfs(index, path):
# 매번 결과 추가
result.append(path)
print(index, path)
print(result)
# 경로를 만들면 DFS
for i in range(index, len(nums)):
dfs(i+1, path+[nums[i]])
dfs(0, [])
return result
Subscribe via RSS