This commit is contained in:
parent
22857619c1
commit
149a0df863
1 changed files with 14 additions and 0 deletions
14
easy/counting_words_with_a_given_prefix.py
Normal file
14
easy/counting_words_with_a_given_prefix.py
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
# https://leetcode.com/problems/counting-words-with-a-given-prefix
|
||||||
|
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
class Solution:
|
||||||
|
def prefixCount(self, words: List[str], pref: str) -> int:
|
||||||
|
result = 0
|
||||||
|
l = len(pref)
|
||||||
|
for word in words:
|
||||||
|
if len(word) >= l and word[:l] == pref:
|
||||||
|
result += 1
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue