Skip to content

LC: Construct Binary Tree from String

ErdemT09 edited this page Aug 4, 2021 · 2 revisions

Construct Binary Tree from String

The Essence:

The binary tree data structure is recursively defined. So is the string that represents this data structure in this problem. When a parentheses is encountered, the next node can be recursively parsed to be the left or right node of the current root.

Details:

For this recursive definition of the string, a stack or recursion can be used. Closed-parenthesis would represent end of a parsing of the node too.

Clone this wiki locally