145. Binary Tree Postorder Traversal

Description

Given the root of a binary tree, return the postorder traversal of its nodes' values.

Constraints

  • The number of the nodes in the tree is in the range [0, 100].

  • -100 <= Node.val <= 100

Approach

  • GeeksforGeeks

  • ProgramCreek

  • YouTube

Examples

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

Output: [3, 2, 1]

Solutions

// Definition for a binary tree node.
public class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    
    TreeNode() {}
    
    TreeNode(int val) { this.val = val; }
    
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

Follow up

Last updated

Was this helpful?