LeetCode solutions

1156. Occurrences After Bigram

My accepted C++ solution to LeetCode problem 1156, Occurrences After Bigram, running in 0ms.

  • Difficulty: Easy
  • C++
  • Runtime 0ms
  • Memory 9.2MB

Read the problem on LeetCode View on GitHub

C++

Accepted on LeetCode — runtime 0ms, memory 9.2MB, accepted 2025-12-28.

cpp
class Solution {
    public:
    vector<string> findOcurrences(string text, string first, string second) {
        vector<string> result;
        istringstream iss(text);
        vector<string> words;
        string word;
        while (iss >> word) words.push_back(word);

        for (int i = 0; i + 2 < words.size(); i++) {
            if (words[i] == first && words[i+1] == second) {
                result.push_back(words[i+2]);
            }
        }
        return result;
    }
};

Source