Find Words That Can Be Formed by Characters LeetCode solution in Python

1
class Solution(object):
2
def countCharacters(self, words, chars):
3
"""
4
:type words: List[str]
5
:type chars: str
6
:rtype: int
7
"""
8
b = set(chars)
9
anwser = 0
10
for i in words:
11
a = set(i)
12
if a.issubset(b):
13
test = [o for o in a if chars.count(o) < i.count(o)]
14
if len(test) == 0:
15
anwser += len(i)
16
return anwser

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0