652. Find Duplicate Subtrees
题目描述
Given a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only need to return the root node of any one of them.
Two trees are duplicate if they have the same structure with same node values.
|
|
The following are two duplicate subtrees:
|
|
and
|
|
Therefore, you need to return above trees’ root in the form of a list.
题目大意
寻找重复子树
解题思路
采用辅助字典
利用字符串模拟树形结构,以字符串为key,当字典值为2时,则表示有相等的树,返回此树即可。
代码
|
|