5516. 警告一小时内使用相同员工卡大于等于三次的人
class Solution {
public:
vector<string> alertNames(vector<string>& keyName, vector<string>& keyTime) {
map<string, set<string> > mp;
int n = keyName.size();
for(int i = 0;i < n;i++) mp[keyName[i]].insert(keyTime[i]);
vector<string> ans;
for(auto p : mp){
string name = p.first;
if(check(p.second)) ans.push_back(name);
}
return ans;
}
private:
bool check(set<string> p){
if(p.size()<=2) return false;
vector<string> v(p.begin(),p.end());
for(auto i = 0;i+2<v.size();i++){
if(checkTime(v[i],v[i+2])) return true;
}
return false;
}
bool checkTime(string l,string r){
int s = getTime(l);
int e = getTime(r);
if(e-s<=60) return true;
return false;
}
int getTime(string s){
int ans = 0;
ans =atoi(s.substr(0,2).c_str())*60+atoi(s.substr(3,2).c_str());
return ans;
}
};