LeetCode 2933. 高访问员工
原题链接
中等
作者:
我是java同学
,
2023-11-12 16:25:50
,
所有人可见
,
阅读 78
class Solution {
public:
vector<string> findHighAccessEmployees(vector<vector<string>>& access_times) {
unordered_map<string, vector<int>> groups;
for (auto p: access_times) {
string name = p[0], s = p[1];
int t = stoi(s.substr(0, 2)) * 60 + stoi(s.substr(2));
groups[name].push_back(t);
}
vector<string> res;
for (auto& [name, a]: groups) {
sort(a.begin(), a.end());
for (int i = 2; i < a.size(); i ++ )
if (a[i] - a[i - 2] < 60) {
res.push_back(name);
break;
}
}
return res;
}
};
class Solution {
public:
vector<string> findHighAccessEmployees(vector<vector<string>>& at) {
vector<string> res;
unordered_set<string> hash;
sort(at.begin(), at.end());
int n = at.size();
for (int i = 0; i < n; i ++ ) {
string name = at[i][0];
int time = stoi(at[i][1].substr(0, 2)) * 60 + stoi(at[i][1].substr(2));
int cnt = 1;
for (int j = i + 1; j < n; j ++)
if (at[j][0] == name) {
int t = stoi(at[j][1].substr(0, 2)) * 60 + stoi(at[j][1].substr(2));
if (abs(time - t) < 60) cnt ++ ;
} else break;
if (cnt >= 3) hash.insert(name);
}
for (auto s: hash) res.push_back(s);
return res;
}
};