标签:map get loading name 相同 vat alert fir ret
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;
}
};
标签:map get loading name 相同 vat alert fir ret
原文地址:https://www.cnblogs.com/shuibeng/p/13766098.html