Given a binary tree, collect a tree’s nodes as if you were doing this: Collect and remove all leaves, repeat until the tree is empty.
Example
No.1
Input: {1,2,3,4,5}
Output: [[4, 5, 3], [2], [1]].
Explanation:
1 | 1 |
No.2
Input: {1,2,3,4}
Output: [[4, 3], [2], [1]].
Explanation:
1 | 1 |
Code
1 | public class TreeNode { |
1 | public List<List<Integer>> findLeaves(TreeNode root) { |