调试中...
调试中...
题目描述
题目描述
题解
题解
提交记录
提交记录
代码
代码
测试用例
测试用例
测试结果
测试结果
简单
相关标签
相关企业
提示

给定一个字符串数组 words 和一个字符串 chars

如果字符串可以由 chars 中的字符组成(每个字符在 每个 words 中只能使用一次),则认为它是好的。

返回 words 中所有好的字符串的长度之和。

 

示例 1:

输入:words = ["cat","bt","hat","tree"], chars = "atach"
输出:6
解释: 
可以形成字符串 "cat" 和 "hat",所以答案是 3 + 3 = 6。

示例 2:

输入:words = ["hello","world","leetcode"], chars = "welldonehoneyr"
输出:10
解释:
可以形成字符串 "hello" 和 "world",所以答案是 5 + 5 = 10。

 

提示:

  • 1 <= words.length <= 1000
  • 1 <= words[i].length, chars.length <= 100
  • words[i] 和 chars 中都仅包含小写英文字母
通过次数
84.6K
提交次数
124K
通过率
68.2%


相关企业

提示 1
Solve the problem for each string in words independently.

提示 2
Now try to think in frequency of letters.

提示 3
Count how many times each character occurs in string chars.

提示 4
To form a string using characters from chars, the frequency of each character in chars must be greater than or equal the frequency of that character in the string to be formed.


评论 (0)

贡献者
© 2025 领扣网络(上海)有限公司
0 人在线
行 1,列 1
运行和提交代码需要登录
words =
["cat","bt","hat","tree"]
chars =
"atach"
Source