mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-12 08:55:14 +08:00
36 lines
1.2 KiB
HTML
36 lines
1.2 KiB
HTML
<p>给定一个字符串数组 <code>words</code> 和一个字符串 <code>chars</code>。</p>
|
||
|
||
<p>如果字符串可以由 <code>chars</code> 中的字符组成(每个字符在 <strong>每个</strong> <code>words</code> 中只能使用一次),则认为它是好的。</p>
|
||
|
||
<p>返回 <code>words</code> 中所有好的字符串的长度之和。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>words = ["cat","bt","hat","tree"], chars = "atach"
|
||
<strong>输出:</strong>6
|
||
<strong>解释: </strong>
|
||
可以形成字符串 "cat" 和 "hat",所以答案是 3 + 3 = 6。
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>words = ["hello","world","leetcode"], chars = "welldonehoneyr"
|
||
<strong>输出:</strong>10
|
||
<strong>解释:</strong>
|
||
可以形成字符串 "hello" 和 "world",所以答案是 5 + 5 = 10。
|
||
</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= words.length <= 1000</code></li>
|
||
<li><code>1 <= words[i].length, chars.length <= 100</code></li>
|
||
<li><code>words[i]</code> 和 <code>chars</code> 中都仅包含小写英文字母</li>
|
||
</ul>
|