File tree Expand file tree Collapse file tree 1 file changed +63
-0
lines changed Expand file tree Collapse file tree 1 file changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+
4
+ bool static comp (string s1,string s2){
5
+ int h1 = (s1[0 ]-' 0' )*10 + (s1[1 ]-' 0' );
6
+ int h2 = (s2[0 ]-' 0' )*10 + (s2[1 ]-' 0' );
7
+ if (h1!=h2){
8
+ return h1<h2;
9
+ }
10
+ int m1 = (s1[3 ]-' 0' )*10 + (s1[4 ]-' 0' );
11
+ int m2 = (s2[3 ]-' 0' )*10 + (s2[4 ]-' 0' );
12
+ return m1<=m2;
13
+ }
14
+ vector<string> alertNames (vector<string>& keyName, vector<string>& keyTime) {
15
+ map<string,vector<string>>h;
16
+ for (int i=0 ;i<keyName.size ();i++){
17
+ h[keyName[i]].push_back (keyTime[i]);
18
+ }
19
+ vector<string>ans;
20
+ for (auto it=h.begin ();it!=h.end ();it++){
21
+ vector<string>v = it->second ;
22
+ if (v.size ()>=3 ){
23
+ sort (v.begin (),v.end (),comp);
24
+ }
25
+ int count=1 ;
26
+ int i=0 ,j=1 ;
27
+ while (j<v.size ()){
28
+ int h1=(v[i][0 ]-' 0' )*10 + (v[i][1 ]-' 0' );
29
+ int h2=(v[j][0 ]-' 0' )*10 + (v[j][1 ]-' 0' );
30
+ if (h1==h2){
31
+ count++;
32
+ if (count>=3 ){
33
+ ans.push_back (it->first );
34
+ break ;
35
+ }
36
+ j++;
37
+ }else {
38
+ if (h2==h1+1 ){
39
+ int m1 = (v[i][3 ]-' 0' )*10 + (v[i][4 ]-' 0' );
40
+ int m2 = (v[j][3 ]-' 0' )*10 + (v[j][4 ]-' 0' );
41
+ if (60 -m1+m2<=60 ){
42
+ count++;
43
+ if (count>=3 ){
44
+ ans.push_back (it->first );
45
+ break ;
46
+ }
47
+ j++;
48
+ }else {
49
+ i++;
50
+ count--;
51
+ }
52
+ }else {
53
+ i++;
54
+ count--;
55
+ }
56
+ }
57
+ }
58
+
59
+ }
60
+ return ans;
61
+
62
+ }
63
+ };
You can’t perform that action at this time.
0 commit comments