2255. Count Prefixes of a Given String
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 74% Topics: Array, String
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n * l)
# Space: O(1)
import itertools
# string
class Solution(object):
def countPrefixes(self, words, s):
"""
:type words: List[str]
:type s: str
:rtype: int
"""
return sum(itertools.imap(s.startswith, words))
Solution from kamyu104/LeetCode-Solutions · MIT