-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathHistorical_Clickstream.cpp
More file actions
44 lines (43 loc) · 1.19 KB
/
Historical_Clickstream.cpp
File metadata and controls
44 lines (43 loc) · 1.19 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
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
vector<string> historicalurl(vector<string> &user1, vector<string> &user2)
{
int n = user1.size(), m = user2.size();
int dp[n + 1][m + 1];
memset(dp, 0, sizeof(dp));
int len = 0, pos = 0;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
if (user1[i - 1] != user2[j - 1])
{
dp[i][j] = 0;
continue;
}
dp[i][j] = 1 + dp[i - 1][j - 1];
if (dp[i][j] > len)
{
len = dp[i][j];
pos = i - len;
}
}
}
vector<string> ans;
for (int i = pos; i < pos + len; i++)
ans.push_back(user1[i]);
return ans;
}
};
int main()
{
vector<string> user1 = {"/home", "/register", "/login", "/user", "/one", "/two"};
vector<string> user2 = {"/home", "/red", "/login", "/user", "/one", "/pink"};
Solution obj;
vector<string> ans = obj.historicalurl(user1, user2);
for (auto &x : ans)
cout << x << " ";
}