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.
Example
The following are two duplicate subtrees:
and
Therefore, you need to return above trees' root in the form of a list.
Note
Time: O(N^2)
Space: O(N^2)
Code
Last updated