Zepruv › Coding problems

Binary Tree Inorder Traversal

Easy · Stack, Tree, Depth-First Search, Binary Tree

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

Example 1

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

Example 2

Input: root = [1,2,3,4,5,null,8,null,null,6,7,9]
Output: [4,2,6,5,7,1,3,9,8]

Example 3

Input: root = []
Output: []

Example 4

Input: root = [1]
Output: [1]

Constraints

Starter code (python)

# Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution(object):
    def inorderTraversal(self, root):
        """
        :type root: Optional[TreeNode]
        :rtype: List[int]
        """
        

Related problems

Previous: Reverse Linked List II · Next: Unique Binary Search Trees · All problems

Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.