1题目描述
2题解-counter
class Solution:
def countCharacters(self, words: List[str], chars: str) -> int:
chars_counter=collections.Counter(chars)
ans=0
for word in words:
word_counter=collections.Counter(word)
for c in word_counter:
if word_counter[c]>chars_counter[c]:
break
else:
ans+=len(word)
return ans