1160. Find Words That Can Be Formed by Characters

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1160

class Solution:
    def countCharacters(self, words: List[str], chars: str) -> int:
        cnt = Counter(chars)
        res = 0
        for w in words:
            wc = Counter(w)
            if all(cnt[c] >= v for c, v in wc.items()):
                res += len(w)
        return res