1112. Find Words That Can Be Formed by Characters
My accepted Python solution to LeetCode problem 1112, Find Words That Can Be Formed by Characters, running in 71ms.
- Difficulty: Easy
- Python
- Runtime 71ms
- Memory 17.9MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 71ms, memory 17.9MB, accepted 2026-01-02.
class Solution:
def countCharacters(self, words: List[str], chars: str) -> int:
from collections import Counter
chars_count = Counter(chars)
result = 0
for word in words:
word_count = Counter(word)
can_form = True
for c, count in word_count.items():
if chars_count[c] < count:
can_form = False
break
if can_form:
result += len(word)
return result