[Java] Leetcode 145. Binary Tree Postorder Traversal (Iteratively & Recursively) [Binary Tree #3]

preview_player
Показать описание
In this video, I'm going to show you how to solve Leetcode 145. Binary Tree Postorder Traversal (Iteratively & Recursively) which is related to Binary Tree.

Here’s a quick rundown of what you’re about to learn:

⭐️ Course Contents ⭐️
⌨️ (0:00) Recursive Solution
⌨️ (4:09) Iterative (Similar to Preorder traversal)
⌨️ (8:40) Iterative (Remove Tree connections)
⌨️ (12:45) Iterative (Using two pointers)

In the end, you’ll have a really good understanding on how to solve Leetcode 145. Binary Tree Postorder Traversal (Iteratively & Recursively) and questions that are similar to this Binary Tree.

Рекомендации по теме
Комментарии
Автор

Thanks for the 2nd and 3rd approach and not just taking the lazy way out of reversing the answer.

oooo-rcyf
Автор

Thanks again Eric! I came up with another alternative that uses the stack. Only push the left elements in the stack and add the right element to the result list/queue.
```
result = collections.deque()
stack = []

while stack or root:
while root:
result.appendleft(root.val)
stack.append(root.left)
root = root.right

root = stack.pop()

return result
```

jeroenvandenheuvel
Автор

Thanks for sharing, great videos!

Just a quick question (16:00): we may not need "cur = null" in line 35, since we fall into the outer "else" branch when "cur == null", and we never change the cur inside this branch (in other words, cur is always equal to null in this branch) ?

pengx
Автор

Nice explanation! BTW, what is the extension you are using for drawing? Pretty cool.

jinpenglv
Автор

In line 25 why we are mentioning in 0th index we are adding top.val? What if we do like res.add(top.val) ?

amitbhattacharya
visit shbcf.ru