python-algorithm

leetcode 1684. Count the Number of Consistent Strings

무적김두칠 2023. 1. 22. 00:02

https://leetcode.com/problems/count-the-number-of-consistent-strings/description/

 

Count the Number of Consistent Strings - LeetCode

Count the Number of Consistent Strings - You are given a string allowed consisting of distinct characters and an array of strings words. A string is consistent if all characters in the string appear in the string allowed. Return the number of consistent st

leetcode.com

 

1
2
3
4
5
6
7
8
9
class Solution:
    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:
        answer = 0
        for word in words:
            for alphabet in allowed:
                word = word.replace(alphabet,'')
            if word == '':
                answer+=1
        return answer
cs
반응형