-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyzeUserWebsiteVisitPattern1152.cpp
More file actions
56 lines (55 loc) · 1.78 KB
/
analyzeUserWebsiteVisitPattern1152.cpp
File metadata and controls
56 lines (55 loc) · 1.78 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
56
class Solution {
public:
void go (int start, int count, vector<string>& tmp, vector<string>& web, unordered_set<string>& uniq) {
if (count == 3) {
string temp;
for (int i = 0; i < 3; i++) {
temp+=tmp[i];
temp+=" ";
}
//cout << temp << endl;
uniq.insert(temp);
return;
}
//if (start >= web.size()) return;
for (int i = start; i < web.size(); i++) {
tmp.push_back(web[i]);
go (i+1, count+1, tmp, web, uniq);
tmp.pop_back();
}
}
vector<string> mostVisitedPattern(vector<string>& username, vector<int>& timestamp, vector<string>& website) {
unordered_map<string, vector<pair<int, string>>>uw;
vector<string>ans;
for (int i = 0; i < username.size(); i++) {
uw[username[i]].push_back({timestamp[i], website[i]});
}
unordered_map<string, int>count;
string Ans, tmp;
int big = 0;
vector<string>temp;
for (auto& it: uw) {
vector<string>web;
sort(it.second.begin(), it.second.end());
for (auto& iter : it.second) web.push_back(iter.second);
unordered_set<string>uniq;
go (0, 0, temp, web, uniq);
for (auto& s : uniq) {
//cout << s << endl;
count[s]++;
if (count[s] > big) {
big = count[s];
Ans = s;
} else if (count[s] == big && s < Ans) {
Ans = s;
}
}
}
istringstream iss(Ans);
for (int i = 0; i < 3; i++) {
iss >> tmp;
ans.push_back(tmp);
}
return ans;
}
};