python-algorithm

leetcode 2185. Counting Words With a Given Prefix

무적김두칠 2022. 3. 17. 10:25

1
2
3
4
5
6
7
class Solution:
    def prefixCount(self, words: List[str], pref: str-> int:
        prefLength=len(pref)
        cnt=0
        for i in words:
            if i[:prefLength]==pref : cnt+=1
        return cnt
cs
반응형