Skip to content

Instantly share code, notes, and snippets.

@inspirit941
Created October 31, 2020 12:28
Show Gist options
  • Save inspirit941/472ecb4ee90e3f7a3ebd75f97aa1e92d to your computer and use it in GitHub Desktop.
Save inspirit941/472ecb4ee90e3f7a3ebd75f97aa1e92d to your computer and use it in GitHub Desktop.
class Solution:
def subsets(self, nums: List[int]) -> List[List[int]]:
# 트리 구조의 dfs로 해결하기
result = []
def dfs(idx, path):
result.append(path)
# idx 순서대로 경로를 만들면서 dfs 연산
for next_idx in range(idx, len(nums)):
dfs(next_idx + 1, path + [nums[next_idx]])
dfs(0, [])
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment