The problem. Given the root of a binary tree, return its left view: the values you would see standing to the left of the tree — the first (leftmost) node of every level, from top to bottom.
Input: root = [1, 2, 3, 4, 5, 6, 7, null, 8] Output: [1, 2, 4, 8]
Input: root = [1, null, 2, null, 3] Output: [1, 2, 3]
Input: root = [] Output: []It's tempting to just follow left children down from the root — but that's wrong: on a level where the left side has run out, the leftmost node may be a right child, deep in the right subtree. The second example has no left children at all. What we need is the first node of each level.
Free account
Sign up to read the rest of this lesson: 6 more sections, 2 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++.
Still to come