1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-12 17:05:15 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (Chinese)/拼写单词 [find-words-that-can-be-formed-by-characters].html
2025-09-29 14:43:44 +08:00

36 lines
1.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给定一个字符串数组&nbsp;<code>words</code>&nbsp;和一个字符串 <code>chars</code></p>
<p>如果字符串可以由 <code>chars</code> 中的字符组成(每个字符在 <strong>每个</strong>&nbsp;<code>words</code> 中只能使用一次),则认为它是好的。</p>
<p>返回&nbsp;<code>words</code>&nbsp;中所有好的字符串的长度之和。</p>
<p>&nbsp;</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>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= words.length &lt;= 1000</code></li>
<li><code>1 &lt;= words[i].length, chars.length&nbsp;&lt;= 100</code></li>
<li><code>words[i]</code>&nbsp;&nbsp;<code>chars</code> 中都仅包含小写英文字母</li>
</ul>