Skip to content

path [terminology]

Terminology

Usage

  • Use for the mutable sequence of choices made along the current backtracking branch.
  • It differs from res, which stores completed solutions.
  • Restore path after recursive exploration.
res = []
path = []
def dfs(i):
    if i == len(digits):
        res.append("".join(path))
        return
    for ch in phone[digits[i]]:
        path.append(ch)   # choose
        dfs(i + 1)        # explore
        path.pop()        # un-choose
dfs(0)

See 17. Letter Combinations of a Phone Number.