Loading problem...
Given the root node of a binary tree, enumerate and return all possible paths that traverse from the root node down to any leaf node. The paths can be returned in any order.
A leaf node is defined as a node that has no children (both left and right child references are null).
Each path should be represented as a string consisting of node values separated by the arrow symbol "->", indicating the traversal direction from parent to child.
root = [1,2,3,null,5]["1->2->5","1->3"]The tree has two paths from root to leaves: The path 1 → 2 → 5 traverses through the left subtree, reaching leaf node 5. The path 1 → 3 goes directly to the right child, which is a leaf node.
root = [1]["1"]The tree contains only a single node (the root), which is also a leaf since it has no children. The only path is the root itself.
root = [1,2,3]["1->2","1->3"]The root node 1 has two children: 2 (left) and 3 (right). Both children are leaf nodes since they have no children, resulting in two paths from root to leaves.
Constraints