Subsets with a shared path list. Output is a list of empty lists. Why?
def dfs(i):
res.append(path)
for j in range(i, len(nums)):
path.append(nums[j]); dfs(j + 1); path.pop()Show answer
Answer
It appends the same list object, so later pops empty every entry
res holds references to one list that ends empty. Append path[:] or list(path). Starting from j allows reuse, a different problem. Popping before recursing drops the element. A set cannot hold lists and does not fix aliasing.
Source: LeetCode 78. Subsets