2185. Counting Words With a Given Prefix Solution 1 (time O(mn), space O(1)) class Solution(object): def prefixCount(self, words, pref): """ :type words: List[str] :type pref: str :rtype: int """ return sum(w.startswith(pref) for w in words)