-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalertNames.cpp
More file actions
25 lines (25 loc) · 870 Bytes
/
alertNames.cpp
File metadata and controls
25 lines (25 loc) · 870 Bytes
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
class Solution {
public:
vector<string> alertNames(vector<string>& keyName, vector<string>& keyTime) {
map<string, vector<int>> m;
for (int i = 0; i < keyName.size(); ++i)
m[keyName[i]].push_back(std::stoi(keyTime[i].substr(0, 2)) * 60 + std::stoi(keyTime[i].substr(3)));
vector<string> ans;
ans.reserve(m.size());
auto check = [&](vector<int> &v) -> bool {
sort(v.begin(), v.end());
for (int l = 0, r = 0; r < v.size(); ++r) {
while (v[r] - v[l] > 60) ++l;
if (r - l >= 2) return true;
}
return false;
};
for (auto &[name, v]: m) {
if (v.size() > 48) {
ans.push_back(name);
}
else if (check(v)) ans.push_back(name);
}
return std::move(ans);
}
};