Click here to see the full article post
How about this case [1,2,3,null,null,null,4] ?
The expected answer is "1(2)(3()(4))", not sure why we omit the other two "()()".
@Cornelius194968 For leaf nodes we only have to print the value of that node.
Good solution but a mirror mistake on iterative version: Since you use String Concatenation "+", every time you do a string concatenation, it declares a new string rather than add after the previous result string. It consumes lots of memory when the string grows. Should consider using StringBuilder/StringBuffer.
@new2500 Yes you are right. I have replaced the string by StringBuilder. THanks.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.