The TransCompilator

Solved LeetCode program · 438 of 1,000

#0606 · Construct String from Binary Tree

Medium String chunk-09.md

Original English source

Keep a shared values holding 1, 2, 3, and 4. Keep a shared lefts holding 1, -1, -1, and -1. Keep a shared rights holding 2, 3, -1, and -1. Keep a shared built as empty text.
To cover from node (a whole number) with side (a whole number). Place "(" into built. Shape from node. Place ")" into built.

To shape from node (a whole number). If node is less than 0, return. The piece is format whole number item node of values as text. Place piece into built. The left is item node of lefts. The right is item node of rights. If left is less than 0 and right is less than 0, return. If left is at least 0 and right is at least 0, cover from left with 0, cover from right with 1, return. If left is at least 0, cover from left with 0, return. Place "()" into built. Cover from right with 1.

Shape from 0. Show built.

Open in Playground Browse all 1,000 problems

Expected stdout

1(2()(4))(3)