Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

No one has replied

A

As far as every possible solution will take minimum O(n) we can assume that it's constant space complexity

P

This is a very nice solution. I spent so much time on iterative pre-order but couldn't make it work. Seems for this problem you have to use some post-order like iterative traversal.

I must say, you are doing it in the wrong way.

retVec.insert(retVec.begin(),pCur->val); will take O(N) time to complete and you algorithm is basically O(N^2)

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.