0094. Inorder Traversal
Easy | Tree + Traversal | 20 ms (99.17%), 13.9 MB (98.55%)
Last updated
Was this helpful?
Easy | Tree + Traversal | 20 ms (99.17%), 13.9 MB (98.55%)
Last updated
Was this helpful?
Source: GitHub:
Given the root
of a binary tree, return the inorder traversal of its nodes' values.
Pop the stack to retrieve the tuple/pair with the current node and visited status.
If already being visited, we could append the node's value to the answer.
If not:
First, push the right-child node with non-visited status (if the node exists)
Second, push the current node but with visited status
Last, push the left-child node with non-visited status (if the node exists)