Leetcode Problem 606. Construct String from Binary Tree
606. Construct String from Binary Tree
Leetcode Solutions
Recursive Preorder Traversal
Start with the root node of the binary tree.
If the current node is null, return an empty string.
Convert the value of the current node to a string and append it to the result.
Recursively call the function for the left child. If the left child is not null, enclose the result of the recursion in parentheses and append it to the result string.
Recursively call the function for the right child. If the right child is not null but the left child is, append an empty pair of parentheses before appending the result of the right child recursion enclosed in parentheses.
If both children are null, do not append any parentheses.