Skip to Main Content

Binary Tree Postorder Traversal

Problem URL:Binary Tree Postorder Traversal

My Solution

Python

Recursive Approach

# Definition for a binary tree node.
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


def postorderTraversal(root: Optional[TreeNode]) -> List[int]:
    if not root:
        return []

    return [*postorderTraversal(root.left), *postorderTraversal(root.right), root.val]

Let's Connect

Twitter GitHub LinkedIn