Skip to content

Commit f231f1d

Browse files
committed
Runtime: 41 ms (Top 93.16%) | Memory: 44.5 MB (Top 70.83%)
1 parent e7000fe commit f231f1d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1+
// Runtime: 41 ms (Top 93.16%) | Memory: 44.5 MB (Top 70.83%)
12
class Solution {
23
public:
34
unordered_map<string,int> dp ;
45
vector<TreeNode*> ans ;
5-
6+
67
string solve(TreeNode * root){
78
if(!root) return "" ;
8-
9+
910
string left = solve(root->left) ;
1011
string right = solve(root->right) ;
11-
12+
1213
string code = to_string(root->val) + " " + left + " " + right ;
1314
if(dp[code] == 1) ans.push_back(root) ;
1415
dp[code]++ ;
15-
16+
1617
return code ;
1718
}
18-
19+
1920
vector<TreeNode*> findDuplicateSubtrees(TreeNode* root) {
2021
string dummy = solve(root) ;
2122
return ans ;
2223
}
23-
};
24+
};

0 commit comments

Comments
 (0)