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.
I have similar question as 'Cornelius194968'. For input [1,2,null,3,4], my answer is "1(2(3)(4))()", while the expected answer is "1(2(3)(4))". I think my answer is correct. Otherwise the input of [1,2,3,4] and [1,2,null,3,4] generates the same output. Obviously that's not correct.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.