0606. Construct String from Binary Tree

https://leetcode.com/problems/construct-string-from-binary-tree

Description

Given the root of a binary tree, construct a string consists of parenthesis and integers from a binary tree with the preorder traversing 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

ac

Last updated

Was this helpful?