Formatted question description: https://leetcode.ca/all/366.html
366 Find Leaves of Binary Tree 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: Input: [1,2,3,4,5] 1 / \ 2 3 / \ 4 5 Output: [[4,5,3],,] Explanation: 1. Removing the leaves [4,5,3] would result in this tree: 1 / 2 2. Now removing the leaf  would result in this tree: 1 3. Now removing the leaf  would result in the empty tree:  @tag-tree
Each node is separated from the left child node and the right child node to get two depths,
Since the condition of becoming a leaf node is that the left and right child nodes are empty, we take the larger value of the left and right child nodes plus 1 as the depth value of the current node.
Knowing the depth value, you can add the node value to the correct position in the result.