Skip to Main Content

Binary Tree Inorder Traversal

Problem URL:Binary Tree Inorder 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 inorderTraversal(root: Optional[TreeNode]) -> List[int]:
    if not root:
        return []

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

Let's Connect

Twitter GitHub LinkedIn