Construct Binary Tree from String
This solution is O(n^2) time.
@soham6 There is no such situation. Pay attention to: An empty tree is represented by "" instead of "()".
@StefanPochmann Yeah, totally understand, I think it is even harder to write a proper assertion program than actually solve this problem. So I think don't bother, just let it crash ;).
No one has replied
In build function, I think you should check whether i < s.size(). For test case "4", you may eventually check "s == '(' ", which is invalid.
Java version based on your idea :-)
@xtermx In this problem, a null subtree is represented by empty string, not by a pair of () contains nothing. But good points, we should make it more clear in the description. Thanks!
Disabled Categories are greyed out
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.