Is using stack still considered as in place in this problem?

  • 2

    For preorder traversal of the tree, you cannot avoid using a stack, either iterative or recursive. So if I use a stack in the problem, is it still considered as in place algorithm?

  • 9

    in-place means modifying the data structure that was passed in directly without cloning the data structure, so I think your method is fine.

  • 0

    using stack is still considerd as in place, but you can improve it to using Morris Traversal Algorithm which just using O(1) space

Log in to reply

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