P18237 [GeeksforGeeks] Duplicate subtrees
普及
题目描述

Given a binary tree of size N, your task is to that find all duplicate subtrees from the given binary tree.
Note: Here's the Output of every Node printed in the Pre-Order tree traversal format. Arrange nodes in the answer array based on the lexicographically increasing order of their preorder traversal of subtree.
For Example: if we have 3 preorder traversal as {1,2,3},{1},{11,2,3} then your lexicographically increasing order is {1},{1,2,3},{11,2,3}, you are supposed to output the head of all these subtrees in the same order.
Example:
Input :
Output : 2 4
4
Explanation: Above Trees are two
duplicate subtrees.i.e and
Therefore,you need to return above trees
root in the form of a list.
Your Task:
You don't need to take input. Just complete the function printAllDups() that takes the root node as a parameter and returns an array of Node*, which contains all the duplicate subtree.
Constraints:
1<=T<=100
1<=N<=100

输入格式

见题面

输出格式

见题面

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