The TransCompilator

Solved LeetCode program · 212 of 1,000

#0257 · Binary Tree Paths

Easy String chunk-05.md

Original English source

Keep a shared values holding 1, 2, 3, and 5. Keep a shared lefts holding 1, -1, -1, and -1. Keep a shared rights holding 2, 3, -1, and -1. Keep a shared path as an empty list of whole numbers. Keep a shared answers as an empty list of text. Keep a shared line as empty text.

To render from spot (a whole number) with last (a whole number). If spot is more than last, return. If spot is more than 0, Place "->" into line. The piece is format whole number item spot of path as text. Place piece into line. Render from spot plus 1 with last.

To store answer. Set line to empty text. The lastpath is the last position of path. Render from 0 with lastpath. The copy is a copy of line. Place copy into answers.

To walk from node (a whole number). If node is less than 0, return. Place item node of values into path. The left is item node of lefts. The right is item node of rights. If left is -1 and right is -1, store answer. If left is at least 0, walk from left. If right is at least 0, walk from right. Remove the last item from path.

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

Open in Playground Browse all 1,000 problems

Expected stdout

1->2->5
1->3