본문 바로가기
python-algorithm

leetcode 1684. Count the Number of Consistent Strings

by 무적김두칠 2023. 1. 22.

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
반응형

'python-algorithm' 카테고리의 다른 글

codeforces 158A - Next Round  (0) 2023.01.25
백준 26560 Periods  (0) 2023.01.24
leetcode 58. Length of Last Word  (0) 2023.01.21
leetcode 2404. Most Frequent Even Element  (0) 2023.01.19
leetcode 2465. Number of Distinct Averages  (0) 2023.01.19

댓글