606. Construct String from Binary Tree
Easy
Last updated
Easy
Last updated
Given the root
of a binary tree, construct a string consisting of parenthesis and integers from a binary tree with the preorder traversal way, and return it.
Omit all the empty parenthesis pairs that do not affect the one-to-one mapping relationship between the string and the original binary tree.
Example 1:
Example 2:
Constraints:
The number of nodes in the tree is in the range [1, 104]
.
-1000 <= Node.val <= 1000
Runtime: 12 ms, faster than 81.67%
Memory Usage: 8.2 MB, less than 43.33%