nonlocal-accumulator-pattern

Status: IN

The diameter solution uses a nested `height` closure that captures and mutates an outer `diameter` variable via `nonlocal`, computing height as the return value while accumulating the diameter as a side effect — a pattern that also appears in other tree problems like binary-tree-tilt.

Source: entries/2026/06/06/diameter-of-binary-tree-solution.md

JSON