Leetcode Problem 144. Binary Tree Preorder Traversal
144. Binary Tree Preorder Traversal
Leetcode Solutions
Iterative Preorder Traversal
Initialize an empty stack, stack, and an output list, result.
If the root is not null, push the root onto the stack.
While the stack is not empty:
a. Pop the top node from the stack and add its value to result.
b. If the popped node has a right child, push it onto the stack.
c. If the popped node has a left child, push it onto the stack.
Return the result list containing the preorder traversal.