Find Players With Zero or One Losses LeetCode solution in C++

1
class Solution {
2
public:
3
vector<vector<int>> findWinners(vector<vector<int>> &matches) {
4
unordered_map<int, int> umap;
5
vector<vector<int>> result(2);
6
for (int i = 0; i < matches.size(); i++) {
7
umap[matches[i][1]]++;
8
}
9
for (auto i = umap.begin(); i != umap.end(); i++) {
10
if (i->second == 1) {
11
result[1].push_back(i->first);
12
}
13
}
14
for (int i = 0; i < matches.size(); i++) {
15
if (umap[matches[i][0]] == 0) {
16
result[0].push_back(matches[i][0]);
17
umap[matches[i][0]] = 1;
18
}
19
}
20

21
sort(result[0].begin(), result[0].end());
22

23
sort(result[1].begin(), result[1].end());
24

25
return result;
26
}
27
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0