Description
Submission
class Solution {
public:
vector<string> findOcurrences(string text, string first, string second) {
vector<string_view> words;
string_view svText {text};
auto it1 = svText.begin();
auto it2 = svText.begin();
for(; it2 != svText.end(); ) {
it2 = find(it1, svText.end(), ' ');
words.push_back(svText.substr(it1 - svText.begin(), it2 - it1));
if(it2 != svText.end()) it1 = next(it2);
}
vector<string> rets;
for(int i = 0; i < words.size() - 1; ++i) {
if(words[i] == first && words[i+1] == second && i + 2 < words.size()) rets.emplace_back(words[i+2]);
}
return rets;
}
};