652. Find Duplicate Subtrees
Medium
Last updated
Medium
Last updated
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.
Two trees are duplicate if they have the same structure with the same node values.
Example 1:
Example 2:
Example 3:
Constraints:
The number of the nodes in the tree will be in the range [1, 5000]
-200 <= Node.val <= 200
將樹轉換為字串記錄在 map 裡面,若出現第二次,將該樹的 root 加入答案陣列。效率有點不美好但是很好懂。