Given the root of a binary tree, return all root-to-leaf paths in the tree as strings in the form a->b->c. Pattern focus: Preorder DFS (Root First). Build the path string while moving downward and record it when a leaf is reached.
root = binary tree root
all root-to-leaf paths as strings
Example 1:
Input:
root = [1,2,3,null,5]
Output:
["1->2->5","1->3"]
Explanation:
The tree has two root-to-leaf paths.
Example 2:
Input:
root = [1]
Output:
["1"]
Explanation:
A single node is also a root-to-leaf path.