{ "data": { "question": { "questionId": "652", "questionFrontendId": "652", "categoryTitle": "Algorithms", "boundTopicId": 1713, "title": "Find Duplicate Subtrees", "titleSlug": "find-duplicate-subtrees", "content": "
Given the root
of 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.
\n\nTwo trees are duplicate if they have the same structure with the same node values.
\n\n\n
Example 1:
\n\n\nInput: root = [1,2,3,4,null,2,4,null,null,4]\nOutput: [[2,4],[4]]\n\n\n
Example 2:
\n\n\nInput: root = [2,1,1]\nOutput: [[1]]\n\n\n
Example 3:
\n\n\nInput: root = [2,2,2,3,null,3,null]\nOutput: [[2,3],[3]]\n\n\n
\n
Constraints:
\n\n[1, 10^4]
-200 <= Node.val <= 200
给定一棵二叉树 root
,返回所有重复的子树。
对于同一类的重复子树,你只需要返回其中任意一棵的根结点即可。
\n\n如果两棵树具有相同的结构和相同的结点值,则它们是重复的。
\n\n\n\n
示例 1:
\n\n\n\n\n输入:root = [1,2,3,4,null,2,4,null,null,4]\n输出:[[2,4],[4]]\n\n
示例 2:
\n\n\n\n\n输入:root = [2,1,1]\n输出:[[1]]\n\n
示例 3:
\n\n\n\n
\n输入:root = [2,2,2,3,null,3,null]\n输出:[[2,3],[3]]\n\n
\n\n
提示:
\n\n[1,10^4]
范围内。-200 <= Node.val <= 200