Skip to content

Commit 9359241

Browse files
Zanger67/leetcodeZanger67/leetcode
Zanger67/leetcode
authored and
Zanger67/leetcode
committed
Updated markdown files
1 parent e347508 commit 9359241

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

markdowns/Questions_By_Code_Length.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Calculations are based on the code files's byte sizes.
5959
| 2206 | [Divide Array Into Equal Pairs](<https://leetcode.com/problems/divide-array-into-equal-pairs>) | Easy | | [solution](<_2206. Divide Array Into Equal Pairs.md>) | c, py | Jun 08, 2024 |
6060
| 3233 | Weekly Contest 408 - q2 - [Find the Count of Numbers Which Are Not Special](<https://leetcode.com/problems/find-the-count-of-numbers-which-are-not-special>) | Medium | Contest | [solution](<_3233. Find the Count of Numbers Which Are Not Special.md>) | java, py | Jul 28, 2024 |
6161
| 1087 | [Brace Expansion](<https://leetcode.com/problems/brace-expansion>) | Medium | | [solution](<_1087. Brace Expansion.md>) | py | Jun 15, 2024 |
62+
| 606 | [Construct String from Binary Tree](<https://leetcode.com/problems/construct-string-from-binary-tree>) | Medium | | [solution](<_606. Construct String from Binary Tree.md>) | java, py | Aug 04, 2024 |
6263
| 2390 | [Removing Stars From a String](<https://leetcode.com/problems/removing-stars-from-a-string>) | Medium | | [solution](<_2390. Removing Stars From a String.md>) | java, py | Jun 02, 2024 |
6364
| 1230 | [Toss Strange Coins](<https://leetcode.com/problems/toss-strange-coins>) | Medium | Weekly Premium | [solution](<_1230. Toss Strange Coins.md>) | c, java, py | Jul 29, 2024 |
6465
| 1992 | [Find All Groups of Farmland](<https://leetcode.com/problems/find-all-groups-of-farmland>) | Medium | | [solution](<_1992. Find All Groups of Farmland.md>) | java, py | Jun 24, 2024 |
@@ -136,7 +137,6 @@ Calculations are based on the code files's byte sizes.
136137
| 1122 | [Relative Sort Array](<https://leetcode.com/problems/relative-sort-array>) | Easy | Daily | [solution](<_1122. Relative Sort Array.md>) | java, py | Jun 11, 2024 |
137138
| 1209 | [Remove All Adjacent Duplicates in String II](<https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string-ii>) | Medium | | [solution](<_1209. Remove All Adjacent Duplicates in String II.md>) | py | Jun 19, 2024 |
138139
| 1171 | [Remove Zero Sum Consecutive Nodes from Linked List](<https://leetcode.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list>) | Medium | | [solution](<_1171. Remove Zero Sum Consecutive Nodes from Linked List.md>) | py | Jun 15, 2024 |
139-
| 606 | [Construct String from Binary Tree](<https://leetcode.com/problems/construct-string-from-binary-tree>) | Medium | | [solution](<_606. Construct String from Binary Tree.md>) | java, py | Aug 04, 2024 |
140140
| 2665 | [Counter II](<https://leetcode.com/problems/counter-ii>) | Easy | | [solution](<_2665. Counter II.md>) | js | Jul 09, 2024 |
141141
| 78 | [Subsets](<https://leetcode.com/problems/subsets>) | Medium | N150 | [solution](<_78. Subsets.md>) | py | Jun 02, 2024 |
142142
| 791 | [Custom Sort String](<https://leetcode.com/problems/custom-sort-string>) | Medium | | [solution](<_791. Custom Sort String.md>) | java | Jun 24, 2024 |

markdowns/_606. Construct String from Binary Tree.md

+43
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,52 @@
2020

2121
## Solutions
2222

23+
- [m606 v2 String Builder.java](<../my-submissions/m606 v2 String Builder.java>)
2324
- [m606.java](<../my-submissions/m606.java>)
2425
- [m606.py](<../my-submissions/m606.py>)
2526
### Java
27+
#### [m606 v2 String Builder.java](<../my-submissions/m606 v2 String Builder.java>)
28+
```Java
29+
/**
30+
* Definition for a binary tree node.
31+
* public class TreeNode {
32+
* int val;
33+
* TreeNode left;
34+
* TreeNode right;
35+
* TreeNode() {}
36+
* TreeNode(int val) { this.val = val; }
37+
* TreeNode(int val, TreeNode left, TreeNode right) {
38+
* this.val = val;
39+
* this.left = left;
40+
* this.right = right;
41+
* }
42+
* }
43+
*/
44+
class Solution {
45+
public String tree2str(TreeNode root) {
46+
return helper(root, new StringBuilder()).toString();
47+
}
48+
49+
public StringBuilder helper(TreeNode curr, StringBuilder sb) {
50+
sb.append(curr.val);
51+
52+
if (curr.left != null) {
53+
sb.append("(");
54+
helper(curr.left, sb);
55+
sb.append(")");
56+
} else if (curr.right != null) {
57+
sb.append("()");
58+
}
59+
if (curr.right != null) {
60+
sb.append("(");
61+
helper(curr.right, sb);
62+
sb.append(")");
63+
}
64+
return sb;
65+
}
66+
}
67+
```
68+
2669
#### [m606.java](<../my-submissions/m606.java>)
2770
```Java
2871
/**

0 commit comments

Comments
 (0)