Skip to content

Commit d14302c

Browse files
committed
Runtime: 20 ms (Top 91.73%) | Memory: 25.3 MB (Top 59.17%)
1 parent 503e322 commit d14302c

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1+
// Runtime: 20 ms (Top 91.73%) | Memory: 25.3 MB (Top 59.17%)
12
class Solution {
23
public:
3-
4+
45
void inorder(TreeNode* root, unordered_map<int,int>& mp){
56
if(root==NULL) return;
6-
7+
78
inorder(root->left, mp);
89
mp[root->val]++;
910
inorder(root->right, mp);
1011
}
11-
12+
1213
vector<int> findMode(TreeNode* root) {
1314
unordered_map<int,int> mp;
1415
int maxf=INT_MIN;
15-
vector<int> ans;
16-
16+
vector<int> ans;
17+
1718
inorder(root, mp);
18-
19+
1920
for(auto i=mp.begin(); i!=mp.end(); i++){
2021
maxf = max(i->second, maxf);
2122
}
22-
23+
2324
for(auto i=mp.begin(); i!=mp.end(); i++){
2425
if(i->second==maxf) ans.push_back(i->first);
2526
}
26-
27+
2728
return ans;
28-
29+
2930
}
30-
};
31+
};

0 commit comments

Comments
 (0)