P20741 [GeeksforGeeks] Number of root to leaf paths
普及
题目描述

Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths.
Example 1:
Input:
3
/ \
2 4
Output:
2 2 $
Explanation :
There are 2 roots to leaf paths
of length 2(3 -> 2 and 3 -> 4)
Example 2:
Input:
10
/ \
20 30
/ \
40 60
Output:
2 1 $3 2 $
Explanation:
There is 1 root leaf paths of
length 2 and 2 roots to leaf paths
of length 3.
Your Task:
Your task is to complete the function pathCounts that prints the path length and the number of root to leaf paths of this length separated by space. Every path length and number of root to leaf path should be separated by "$".
Constraints:
1 <= T <= 30
1 <= Number of nodes <= 100
1 <= Data of a node <= 1000

输入格式

见题面

输出格式

见题面

样例输入
3 / \ 2 4
样例输出
2 2 $