652.Find Duplicate Subtrees
652. Find Duplicate Subtrees
題目描述
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:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Example 2:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Example 3:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Constraints:
- The number of the nodes in the tree will be in the range
[1, 5000]
- -200 <=
Node.val
<= 200
解答
C++
Yen-Chi ChenTue, Feb 28, 2023
Python
Yen-Chi ChenTue, Feb 28, 2023
Time:
Extra Space: 儲存每顆樹的序列string
XD Feb 28, 2023
Reference
回到題目列表