Occurrences After Bigram LeetCode solution in C++

1
class Solution {
2
public:
3
vector<string> findOcurrences(string text, string first, string second) {
4
vector<string> ans;
5
int i = 0;
6
while (i < text.length()) {
7
string word = "";
8
string secondWord = "";
9
while (i < text.length() && text[i] != ' ') {
10
word = word + text[i];
11
i++;
12
}
13
if (word == first) {
14
int k = i + 1;
15
while (k < text.length() && text[k] != ' ') {
16
secondWord = secondWord + text[k];
17
k++;
18
}
19
k++;
20
if (k < text.length() && secondWord == second) {
21
string tmp = "";
22
int j = k;
23
while (j < text.length() && text[j] != ' ') {
24
tmp = tmp + text[j];
25
j++;
26
}
27

28
ans.push_back(tmp);
29
}
30
}
31
i++;
32
}
33
return ans;
34
}
35
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0