2185. Counting Words With a Given Prefix
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 85% Topics: Array, String, String Matching
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n * p)
# Space: O(1)
# string
class Solution(object):
def prefixCount(self, words, pref):
"""
:type words: List[str]
:type pref: str
:rtype: int
"""
return sum(x.startswith(pref) for x in words)
Solution from kamyu104/LeetCode-Solutions · MIT