Occurrences After Bigram LeetCode solution in C++
1class Solution {2public:3vector<string> findOcurrences(string text, string first, string second) {4vector<string> ans;5int i = 0;6while (i < text.length()) {7string word = "";8string secondWord = "";9while (i < text.length() && text[i] != ' ') {10word = word + text[i];11i++;12}13if (word == first) {14int k = i + 1;15while (k < text.length() && text[k] != ' ') {16secondWord = secondWord + text[k];17k++;18}19k++;20if (k < text.length() && secondWord == second) {21string tmp = "";22int j = k;23while (j < text.length() && text[j] != ' ') {24tmp = tmp + text[j];25j++;26}2728ans.push_back(tmp);29}30}31i++;32}33return ans;34}35};