List a Tree's Values Left, Node, Right

Implement inorderValues

You are given the root of a binary tree, where each node holds an integer val and has a left and a right child (either may be missing). Return the values of all nodes in the order you meet them when, at every node, you first walk the entire left subtree, then take the node itself, then walk the entire right subtree.

Writing this as a recursive helper is the direct approach. The same order can also be produced without recursion by keeping your own stack of the nodes that are still waiting for their turn.

Example 1:

Input: root = [4,2,7,1,3,null,9]

Output: [1,2,3,4,7,9]

Example 2:

Input: root = [5,null,8,6]

Output: [5,6,8]

Example 3:

Input: root = []

Output: []

+ 13 hidden test cases run on Submit.

Constraints:

  • ●0 ≤ number of nodes ≤ 100
  • ●−100 ≤ node.val ≤ 100
  • ●The tree is given as its root node (null for an empty tree); each node has a val, a left child and a right child
  • ●Visit every node's left subtree first, then the node itself, then its right subtree, and return the values in the order visited

root =

[4, 2, 7, 1, 3, null, 9]