P18046 [GeeksforGeeks] Duplicate subtree in binary tree
普及
题目描述

Given a binary tree, find out whether it contains a duplicate sub-tree of size two or more, or not.
Note: Two same leaf nodes are not considered as subtree as size of a leaf node is one.
Example 1 :
Input :
1
/ \
2 3
/ \ \
4 5 2
/ \
4 5
Output : 1
Explanation :
2
/ \
4 5
is the duplicate sub-tree.
Example 2 :
Input :
1
/ \
2 3
Output: 0
Explanation: There is no duplicate sub-tree
in the given binary tree.
Your Task:
You don't need to read input or print anything. Your task is to complete the function dupSub() which takes root of the tree as the only argument and returns 1 if the binary tree contains a duplicate sub-tree of size two or more, else 0.
Constraints:
1 ≤ Number of nodes ≤ 100

输入格式

见题面

输出格式

见题面

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