text using this rule: first an integer, the node's value (it may be negative), then zero, one or two pairs of parentheses. Each pair holds a subtree written the same way.
The first pair is always the left subtree and the second one is the right subtree. With only one pair, the node has just a left child. A pair may be empty: () means there is no subtree, which is how a node with only a right child is written, as in 5()(9).
Build the tree and return its root. An empty string means an empty tree.text="7(3(1)(5))(-2(8))" → [7, 3, -2, 1, 5, 8]
The root is 7. The first bracket pair is the left subtree: 3 with children 1 and 5. The second is the right subtree: -2, which has a single pair, so 8 is its left child.
text="12(4)" → [12, 4]
Only one bracket pair, so the root has just a left child.
text="" → None
An empty string is an empty tree.
text consists of digits, (, ) and - and follows the rule abovetext="7(3(1)(5))(-2(8))"
[7, 3, -2, 1, 5, 8]
Run checks the first 3 tests in your browser. Submit checks all 95 tests on the server, hidden ones included.