#1160
Find Words That Can Be Formed by Characters
newbie · 270 · lc easy +19 · verified · 71.5% accepted · 2,253 likes · top 80%
Description
You are given an array of strings words and a string chars.
A word is "good" if every character needed to spell it can be drawn from chars, with each character in chars usable at most once per word.
Return the combined length of all good words.
Example 1:
Input: words = ["cat","bt","hat","tree"], chars = "atach"
Output: 6
Explanation: The strings that can be formed are "cat" and "hat" so the answer is 3 + 3 = 6.
Example 2:
Input: words = ["hello","world","leetcode"], chars = "welldonehoneyr"
Output: 10
Explanation: The strings that can be formed are "hello" and "world" so the answer is 5 + 5 = 10.
Code
1
2
3