This commit is contained in:
Vombit
2026-05-27 12:37:20 +05:00
parent df1dbfd0ae
commit d940e1dd2f
3 changed files with 44 additions and 0 deletions

22
solutions/lc1160.py Normal file
View File

@@ -0,0 +1,22 @@
class Solution:
def countCharacters(self, words: List[str], chars: str) -> int:
answer = 0
char_count = {}
for c in chars:
char_count[c] = char_count.get(c, 0) + 1
for word in words:
word_count = {}
is_valid = True
for ch in word:
word_count[ch] = word_count.get(ch, 0) + 1
if word_count[ch] > char_count.get(ch, 0):
is_valid = False
break
if is_valid:
answer += len(word)
return answer