MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / backtrack

Method backtrack

python/0040-combination-sum-ii.py:7–21  ·  view source on GitHub ↗
(cur, pos, target)

Source from the content-addressed store, hash-verified

5 res = []
6
7 def backtrack(cur, pos, target):
8 if target == 0:
9 res.append(cur.copy())
10 return
11 if target <= 0:
12 return
13
14 prev = -1
15 for i in range(pos, len(candidates)):
16 if candidates[i] == prev:
17 continue
18 cur.append(candidates[i])
19 backtrack(cur, i + 1, target - candidates[i])
20 cur.pop()
21 prev = candidates[i]
22
23 backtrack([], 0, target)
24 return res

Callers

nothing calls this directly

Calls 2

backtrackFunction · 0.50
popMethod · 0.45

Tested by

no test coverage detected