Skip to content

Lc 606 photo #1465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/606 ex1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/606 ex2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ description: "Given the root of a binary tree, construct a string consisting of
Given the root of a binary tree, construct a string consisting of parenthesis and integers from a binary tree with the preorder traversal way.

### Examples

**Example 1:**

![Screenshot of the application](.././../../assets/606%20ex1.png)

**Input:** `root = [1,2,3,4]`
**Output:** `"1(2(4))(3)"`
**Explanation:** Originally, it needs to be `"1(2(4)())(3()())"`, but you need to omit all the unnecessary empty parenthesis pairs. And it will be `"1(2(4))(3)"`

**Example 2:**

![Screenshot of the application](.././../../assets/606%20ex2.png)

**Input:** `root = [1,2,3,null,4]`
**Output:** `"1(2()(4))(3)"`
**Explanation:** Originally, it needs to be `"1(2()(4)())(3()())"`, but you need to omit all the unnecessary empty parenthesis pairs. And it will be `"1(2()(4))(3)"`
Expand Down Expand Up @@ -127,4 +130,4 @@ class Solution:
>Reason: The space complexity is determined by the recursion stack, which in the worst case (unbalanced tree) is O(n), but on average (balanced tree) is O(log n).

### References
**LeetCode Problem:** Construct String from Binary Tree
**LeetCode Problem:** Construct String from Binary Tree
1 change: 1 addition & 0 deletions dsa-solutions/lc-solutions/0600-0699/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading