The problem. Given the root of a binary tree, return all root-to-leaf paths, each written as a string like "1->2->5". A leaf is a node with no children.
Input: root = [1, 2, 3, null, 5]
Output: ["1->2->5", "1->3"]
Input: root = [1]
Output: ["1"]There is exactly one path per leaf, so the job is: walk down, remember the way you came, and write it out each time you reach a leaf. The approaches differ in how they remember the way.
Free account
Sign up to read the rest of this lesson: 6 more sections, 3 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++.
Still to come