Skip to content

Commit ac2145a

Browse files
1078. Occurrences After Bigram.cpp
1 parent 3a90c5c commit ac2145a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

1078. Occurrences After Bigram.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//Runtime: 0 ms, faster than 100.00% of C++ online submissions for Occurrences After Bigram.
2+
//Memory Usage: 8.8 MB, less than 100.00% of C++ online submissions for Occurrences After Bigram.
3+
class Solution {
4+
public:
5+
std::vector<std::string> string_split(std::string str, std::string delimiter){
6+
size_t pos = 0;
7+
std::string token;
8+
std::vector<std::string> result;
9+
while ((pos = str.find(delimiter)) != std::string::npos) {
10+
token = str.substr(0, pos);
11+
result.push_back(token);
12+
str.erase(0, pos + delimiter.length());
13+
}
14+
result.push_back(str);
15+
return result;
16+
}
17+
18+
vector<string> findOcurrences(string text, string first, string second) {
19+
vector<string> split = string_split(text, " ");
20+
vector<string> ans;
21+
22+
for(int i = 0; i < split.size() - 1; i++){
23+
if(split[i] == first && split[i+1] == second && i+2 < split.size()){
24+
ans.push_back(split[i+2]);
25+
}
26+
}
27+
return ans;
28+
}
29+
};

0 commit comments

Comments
 (0)