-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path2225
39 lines (32 loc) · 1.04 KB
/
2225
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class Solution {
public:
vector<vector<int>> findWinners(vector<vector<int>>& matches) {
vector<vector<int>> ans(2); // Initialize the result vector with two empty vectors
unordered_map<int, vector<char>> mp;
// Populate the unordered_map
for (int i = 0; i < matches.size(); i++) {
vector<int> v = matches[i];
int win = v[0];
int loss = v[1];
mp[win].push_back('w');
mp[loss].push_back('l');
}
// Iterate through the unordered_map
for (auto i : mp) {
vector<char> ch = i.second;
sort(ch.begin(), ch.end());
if (ch[0] == 'w') {
ans[0].push_back(i.first);
}
else if (ch[0] == 'l' && ch.size() > 1 && ch[1] == 'w') {
ans[1].push_back(i.first);
}
else if(ch[0] == 'l' && ch.size() ==1)
ans[1].push_back(i.first);
}
// Sort the result vectors
sort(ans[0].begin(), ans[0].end());
sort(ans[1].begin(), ans[1].end());
return ans;
}
};