{ "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, 5000]
-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, 5000]
范围内。-200 <= Node.val <= 200