diff --git a/easy/counting_words_with_a_given_prefix.py b/easy/counting_words_with_a_given_prefix.py new file mode 100644 index 0000000..16fcc2b --- /dev/null +++ b/easy/counting_words_with_a_given_prefix.py @@ -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 + +