-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path1078. Occurrences After Bigram.cpp
51 lines (48 loc) · 1.07 KB
/
1078. Occurrences After Bigram.cpp
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
class Solution {
public:
vector<string> findOcurrences(string text, string first, string second) {
vector<string> ans;
istringstream ss(text);
string prev2,prev,word;
while(ss >> word)
{
if(prev2==first && prev==second)
{
ans.push_back(word);
}
prev2 = prev;
prev = word;
}
return ans;
}
};
//another one
class Solution {
public:
vector<string> findOcurrences(string text, string first, string second) {
vector<string> t;
string tmp;
for(auto &c:text)
{
if(c==' ')
{
t.push_back(tmp);
tmp = "";
}
else
{
tmp+=c;
}
}
t.push_back(tmp);
vector<string> ans;
for(int i=0;i< t.size()-2;i++)
{
if(t[i]==first && t[i+1]==second)
{
ans.push_back(t[i+2]);
}
}
return ans;
}
};