FrontendX
Binary Tree Paths
easy
Description
AI Assistance
Solution
Test Cases
Test Result
Submissions
Canvas
Binary Tree
Paths
Given the root of a binary tree, return all root-to-leaf paths as a list of strings.
Examples
Example 1
Input:
[1,2,3,null,5]
Output:
["1->2->5","1->3"]
Example 2
Input:
[1]
Output:
["1"]
Hints
Hint 1
Use DFS to traverse from root to leaves.
Hint 2
Build the path string as you traverse.
Hint 3
When reaching a leaf, add the path to the result.
Related Problems
24-game
additive-number
all-paths-from-source-to-target
Binary Tree Paths
Given the root of a binary tree, return all root-to-leaf paths as a list of strings.