# leetcode 2255. Count Prefixes of a Given String（python）

### 描述

You are given a string array words and a string s, where words[i] and s comprise only数组去重 of lowercase English letters.

Return the number of strings字符是什么 in words that are a prefix of s.

A prefix of a string is a sLeetCodeubstring that occurs at the beginning of the string. A substrileetcode高频100题ng数组 is a contiguous sequence of character环路复杂度s within a strleetcode题库ing.

Example 1:

``````Input: words = ["a","b","c","ab","bc","abc"], s = "abc"
Output: 3
Explanation:
The strings in words which are a prefix of s = "abc" are:
"a", "ab", and "abc".
Thus the number of strings in words which are a prefix of s is 3.
``````

Exaleetcode高频100题mple 2:

``````Input: words = ["a","a"], s = "aa"
Output: 2
Explanation:
Both of the strings are a prefix of s.
Note that the same string can occur multiple times in words, and it should be counted each time.
``````

Note:

``````1 <= words.length <= 1000
1 <= words[i].length, s.length <= 10
words[i] and s consist of lowercase English letters only.
``````

### 解答

``````class Solution(object):
def countPrefixes(self, words, s):
"""
:type words: List[str]
:type s: str
:rtype: int
"""
return sum(1 for word in words if s.startswith(word))
``````

### 运行结果python可以做什么工作

``````123 / 123 test cases passed.
Status: Accepted
Runtime: 45 ms
Memory Usage: 13.6 MB
``````

### 原题链接

leetcode.com/contest/biw… 