- Difficulty: Medium
- Type: DFS/BFS
- link
class Solution:
def subsets(self, nums: List[int]) -> List[List[int]]:
result = []
def dfs(start,path):
if start > len(nums):
return
elif start == len(nums):
result.append(path)
return
result.append(path)
for i in range(start,len(nums)):
dfs(i+1,path+[nums[i]])
dfs(0,[])
return result
I found that solution is very popular and helpful: https://youtu.be/NS01_5oZn7c