2255. Count Prefixes of a Given String ¶ Time: $O(n|\texttt{s}|)$ Space: $O(1)$ C++JavaPython 1 2 3 4 5 6 7class Solution { public: int countPrefixes(vector<string>& words, string s) { return ranges::count_if( words, [&](const string& word) { return s.find(word) == 0; }); } }; 1 2 3 4 5class Solution { public int countPrefixes(String[] words, String s) { return (int) Arrays.stream(words).filter(word -> s.startsWith(word)).count(); } } 1 2 3class Solution: def countPrefixes(self, words: list[str], s: str) -> int: return sum(map(s.startswith, words))