Given the root of a binary tree, construct a string consisting of parenthesis and integers from a binary tree with the preorder traversal 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.
root(left)(right) is the answer. So we can do this recursively?
This is a classic recursive question where in order to know the current answer, we need to know the answer beforehand. However, there is one additional requirement from the problem; if the right value is null, then the answer will be the root of the left, but if the left value is null and right is not, then the answer shall be the root of the right. Even though it may not make sense at first, it is a necessary requirement for the problem.