168. Postorder Traversal

Given root of binary tree, return the Postorder traversal of the binary tree.

Example 1:

Input : root = [1, 4, null, 4, 2]

Output : [4, 2, 4, 1]

Explanation :

Example 2:

Input : root = [1, null, 2, 3]

Output : [3, 2, 1]

Explanation :

\

Now Your Turn!

Pick the correct output for the given input

Input : root = [5, 1, 2, 8, null, 4, 5, null, 6]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= Number of Nodes <= 100
  • -100 <= Node.val <= 100

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
/**
* Definition for a binary tree node.
* struct TreeNode {
* int data;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int val) : data(val) , left(nullptr) , right(nullptr) {}
* };
**/
 
class Solution{
public:
vector<int> postorder(TreeNode* root){
//your code goes here
}
};
Test Case

Input:

Root