def dfs(i, path): if i == len(nums): res.append(path[:]) return # include path.append(nums[i]) dfs(i+1, path) path.pop() # exclude dfs(i+1, path)