Skip to content

Commit e88c750

Browse files
authored
Merge pull request neetcode-gh#2361 from singhaniket98/main
0606-construct-string-from-binary-tree.java
2 parents c08a249 + e12f7a9 commit e88c750

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public String tree2str(TreeNode root) {
3+
if(root == null) return "";
4+
String output = String.valueOf(root.val);
5+
if(root.left != null || root.right != null)
6+
output += "(" + tree2str(root.left) + ")";
7+
if(root.right != null)
8+
output += "(" + tree2str(root.right) + ")";
9+
10+
return output;
11+
}
12+
13+
14+
}

0 commit comments

Comments
 (0)