From 149a0df8636e635459728649a54d593e548850f3 Mon Sep 17 00:00:00 2001 From: bumpsoo Date: Thu, 9 Jan 2025 19:59:24 +0900 Subject: [PATCH] https://leetcode.com/problems/counting-words-with-a-given-prefix --- easy/counting_words_with_a_given_prefix.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 easy/counting_words_with_a_given_prefix.py 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 + +