Binary Tree Postorder Traversal - aloalgo

Binary Tree Postorder Traversal

Easy

You are given the root of a binary tree.

Your task is to return the postorder traversal of the values of its nodes.

Note that:

  • In a postorder traversal, you should first visit the left subtree, then the right subtree, and finally the root node itself.

Return a list of integers representing the node values in postorder.

Example 1

Input
123
Output
[3, 2, 1]
Explanation:

The postorder traversal is Left -> Right -> Root. For the given tree, the left subtree is null, the right subtree is node 2 (which has a left child 3), so we visit 3, then 2, then the root 1.

Example 2

Input
None
Output
[]
Explanation:

An empty tree has no nodes, so the traversal is an empty list.

Example 3

Input
4213769
Output
[1, 3, 2, 6, 9, 7, 4]
Explanation:

Following Left -> Right -> Root traversal order results in the sequence [1, 3, 2, 6, 9, 7, 4].

Loading...
Input
123
Output
[3, 2, 1]

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!