2185. Counting Words With a Given Prefix ¶ Time: $O(n)$ Space: $O(1)$ C++JavaPython 1 2 3 4 5 6 7class Solution { public: int prefixCount(vector<string>& words, string pref) { return ranges::count_if( words, [&](const string& word) { return word.find(pref) == 0; }); } }; 1 2 3 4 5class Solution { public int prefixCount(String[] words, String pref) { return (int) Arrays.stream(words).filter(w -> w.startsWith(pref)).count(); } } 1 2 3class Solution: def prefixCount(self, words: list[str], pref: str) -> int: return sum(word.startswith(pref) for word in words)