Home » Java » Java regular expression task [on hold]

Java regular expression task [on hold]

Posted by: admin June 14, 2018 Leave a comment

Questions:

How can I split a string like “4(2(3)(1))(6(5))” into parts like
[4, 2(3)(1), 6(5)]? Basically, the structure of the string is formatted to represent a tree like this “root(left_subtree)(right_subtree)”. This is a recursive definition. I came across this task from trying to solve this problem:

https://www.lintcode.com/problem/construct-binary-tree-from-string/description

I’m not sure how to use regular expressions to solve this in JAVA.

Answers: