Skip to content
This repository was archived by the owner on Sep 22, 2021. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions LeetCode/1160_FindWordsThatCanBeFormedByCharacters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Solution:
def countCharacters(self, words: List[str], chars: str) -> int:
charBins = {char:chars.count(char) for char in chars}
goodWords = []

for word in words:
if (len(word) > len(chars)):
continue

if not set(word).issubset(chars):
continue

letterBins = {letter:word.count(letter) for letter in word}

goodWord = True
for letter in letterBins:
if letterBins[letter] > charBins[letter]:
goodWord = False

if (goodWord):
goodWords.append(word)

return sum(len(word) for word in goodWords)