Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SPACE = ' '
- def subsets(nums):
- res = []
- def dfs(temp, idx):
- print(f"{idx * SPACE}entering dfs({temp},{idx})")
- res.append(temp[:])
- print(f"{idx * SPACE}res:{res}")
- print(f"{idx * SPACE}entering loop")
- for i in range(idx, len(nums)):
- temp.append(nums[i])
- print(f"{i * SPACE}temp:{temp} i:{i} before recursive call")
- dfs(temp,i +1)
- print(f"{i * SPACE}temp:{temp} i:{i} before backtrack")
- temp.pop()
- print(f"{i * SPACE}temp:{temp} i:{i} after backtrack")
- print(f"{idx * SPACE}exiting loop")
- dfs([], 0)
- print("exiting dfs")
- return res
- print(f"\nsubsets: {subsets([1,2,3])}")
Advertisement
Add Comment
Please, Sign In to add comment