2025-08-17 16:10:32 +0000 UTC

Counting Words With a Given Prefix

Code

class Solution:
    def prefixCount(self, words: List[str], pref: str) -> int:
        res = 0
        for word in words:
            if word.startswith(pref):
                res += 1
        return res