What You See Looking at the Tree From the Left

Implement leftEdgeView

You are given the root of a binary tree. Picture yourself standing on its left-hand side, looking towards the tree. At every level you see only the leftmost node of that level; nodes to its right are hidden behind it. Return the values of the visible nodes ordered from the top level to the bottom level.

Building each level completely and taking its first value works. A depth-first walk that always goes left first can find the same values while carrying only the depth.

Example 1:

Input: root = [20,9,31,5,null,null,40,null,null,38]

Output: [20,9,5,38]

Example 2:

Input: root = [6,null,8]

Output: [6,8]

Example 3:

Input: root = []

Output: []

+ 11 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
  • ●Imagine standing to the left of the tree. At each level you see only the leftmost node of that level. Return those visible values from the top level to the bottom. An empty tree gives an empty list

root =

[20, 9, 31, 5, null, null, 40, null, null, 38]