Prefix Matches
A prefix is the beginning of a word, such as "pre" in "prefix". This kind of check is common in search and autocomplete when a user has typed the first few letters. Write a function count_prefixes that receives a list of words and a string pref. Return how many words start with that prefix.
Примеры
Ввод
["pay", "attention", "practice", "attend"], "at"Вывод
2Ввод
["leetcode", "win", "loops", "success"], "code"Вывод
0Ввод
["abc", "abcd", "ab"], "abc"Вывод
2Нужно реализовать
def count_prefixes(words: list[str], pref: str) -> int:
Теги
stringsarray
Log ind for at se indsendelseshistorik
Log indLog ind for at bruge AI-mentor
Log indVisible tests
1
Input
["pay","attention","practice","attend"], "at"Expected
22
Input
["leetcode","win","loops","success"], "code"Expected
03
Input
["abc","abcd","ab"], "abc"Expected
24
Input
[], "x"Expected
05
Input
["go","good","gone"], "go"Expected
36
Input
["a","b","c"], ""Expected
3Focus radio
Paused · SomaFM · Fluid