The TransCompilator

Solved LeetCode program · 571 of 1,000

#0797 · All Paths From Source to Target

Medium Depth-First Search chunk-12.md

Original English source

Keep a shared edges holding 1, 2, 3, and 3. Keep a shared starts holding 0, 2, 3, and 4. Keep a shared counts holding 2, 1, 1, and 0. Keep a shared parts as an empty list of text. Keep a shared answers as an empty list of text. Keep a shared built as empty text.

To expand from node (a whole number) with offset (a whole number). If offset is at least item node of counts, return. The target is item (item node of starts plus offset) of edges. Walk from target. Expand from node with offset plus 1.

To walk from node (a whole number). The piece is format whole number node as text. Place piece into parts. If node is 3, The built is join parts with ",", Place built into answers. If node is not 3, Expand from node with 0. Remove the last item from parts.

Walk from 0. For each answer in answers, show answer.

Open in Playground Browse all 1,000 problems

Expected stdout

0,1,3
0,2,3