Asked at

Binary Tree Inorder Traversal

Easy
Verified
TreeDFSStack~12 min

Given the root of a binary tree, return the inorder traversal of its node values: left subtree, then node, then right subtree.

A node is { val, left, right } with null children; the whole empty tree is null. The input arrives as the root node directly.

Examples

in{val:1, right:{val:2, left:{val:3}}}
out[1, 3, 2]

Left subtree, node, right subtree, applied recursively.

innull
out[]

An empty tree yields no values.

Constraints

  • 0 ≤ number of nodes ≤ 100
  • -100 ≤ node.val ≤ 100

Get help

🔑

Sign in to solve

Sign in to write, run, and submit your solution — and to pick up where your iOS flow left off.