Recursive helper that includes or excludes each element.
(
found: set[tuple[int, ...]],
nums: list[int],
stack: list[int],
position: int,
)
| 33 | |
| 34 | |
| 35 | def _backtrack( |
| 36 | found: set[tuple[int, ...]], |
| 37 | nums: list[int], |
| 38 | stack: list[int], |
| 39 | position: int, |
| 40 | ) -> None: |
| 41 | """Recursive helper that includes or excludes each element.""" |
| 42 | if position == len(nums): |
| 43 | found.add(tuple(stack)) |
| 44 | else: |
| 45 | stack.append(nums[position]) |
| 46 | _backtrack(found, nums, stack, position + 1) |
| 47 | stack.pop() |
| 48 | _backtrack(found, nums, stack, position + 1) |
no test coverage detected