257_Binary Tree Paths
257. Binary Tree Paths
Question
Given a binary tree, return all root-to-leaf paths.Example 1
given the following binary tree:
1
/ \
2 3
\
5
All root-to-leaf paths are:
["1->2->5", "1->3"]Solution 1: recursive
Another version (w/o defining a helper function)
Solution 2: iterative (Depth first search, using stack)
Solution 3: iterative (Breadth first search, using stack) ??
Last updated