-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1152.cpp
More file actions
57 lines (47 loc) · 1.75 KB
/
Copy path1152.cpp
File metadata and controls
57 lines (47 loc) · 1.75 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// Created by 陈语梵 on 2020/8/19.
//
struct LogEntry {
string *username;
int *timestamp;
string *website;
};
class Solution {
public:
vector<string> mostVisitedPattern(vector<string>& username, vector<int>& timestamp, vector<string>& website) {
// username to logs
unordered_map<string, vector<LogEntry>> logEntries;
for (int i = 0; i < username.size(); ++i) {
logEntries[username[i]].push_back(LogEntry{
.username = &username[i],
.timestamp = ×tamp[i],
.website = &website[i]
});
}
for (auto &p : logEntries) {
sort(p.second.begin(), p.second.end(), [](LogEntry& a, LogEntry &b) {
return *a.timestamp < *b.timestamp;
});
}
map<vector<string>, int> cnt;
for (auto &p : logEntries) {
auto &username = p.first;
auto &entries = p.second;
set<vector<string>> picked;
for (int i = 0; i < entries.size(); ++i) {
for (int q = i+1; q < entries.size(); ++q) {
for (int j = q+1; j < entries.size(); ++j) {
if (picked.find({*entries[i].website, *entries[q].website, *entries[j].website})) continue;
picked.insert({*entries[i].website, *entries[q].website, *entries[j].website});
cnt[{*entries[i].website, *entries[q].website, *entries[j].website}]++;
}
}
}
}
auto maxIt = cnt.begin();
for (auto it = cnt.begin(); it != cnt.end(); ++it) {
if ((*maxIt).second < (*it).second) maxIt = it;
}
return (*maxIt).first;
}
};