Given a binary tree, return all root-to-leaf paths.
Note: A leaf is a node with no children.
The most straight forward way to solve this problen is via recursive DFS.
// dfs traverse top down
Add all nodes’s value along the way (top-down) and add path string into
List<String> solution at leaf node.
The bottom up recursive approach is bit harder to come up with. I was not able to come up with it at first place.
DFS iterative approach can pre-order traversal, which is a top-down approach. The bottom-up appraoch is simliar w/ in-order traversal (bottom-up) but not implemented, below is the DFS iterative top-down via pre-order traversal.
// dfs iterative + preorder (top-down)
// bfs iterative + leverl order
- DFS recursive (bottom-up)
- DFS recursive (top-down)
- DFS iterative (top-down, pre-order traversal)
- DFS iterative (bottom-up, in-order traversal)
- BFS iterative
- BFS iterative is similiar to DFS iterative (top-down, preorder)
- 02/04/19: solution added
- TODO: dfs recursive/iterative bottom-up