Skip to content

Commit 061b3cf

Browse files
authored
Create counting-words-with-a-given-prefix.py
1 parent c407ca1 commit 061b3cf

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Time: O(n * p)
2+
# Space: O(1)
3+
4+
# string
5+
class Solution(object):
6+
def prefixCount(self, words, pref):
7+
"""
8+
:type words: List[str]
9+
:type pref: str
10+
:rtype: int
11+
"""
12+
return sum(x.startswith(pref) for x in words)

0 commit comments

Comments
 (0)