Description
Given the root of a binary tree, return all root-to-leaf paths in any order. A leaf is a node with no children.
Examples
Input:
root = [1,2,3,null,5]Output:
["1->2->5","1->3"]Explanation:
Two paths.
Input:
root = [4,7,9,null,null,2,6]Output:
["4->7","4->9->2","4->9->6"]Explanation:
The tree has three root-to-leaf paths: from root 4 to leaf 7, from root 4 through 9 to leaf 2, and from root 4 through 9 to leaf 6.
Input:
root = [8]Output:
["8"]Explanation:
Single node tree where the root is also a leaf, so there's only one path containing just the root node.
Constraints
- •
1 ≤ nodes ≤ 100