1160. Find Words That Can Be Formed by Characters Easy
1/**
2 * [1160] Find Words That Can Be Formed by Characters
3 *
4 * You are given an array of strings words and a string chars.
5 * A string is good if it can be formed by characters from chars (each character can only be used once).
6 * Return the sum of lengths of all good strings in words.
7 *
8 * Example 1:
9 *
10 * Input: words = ["cat","bt","hat","tree"], chars = "atach"
11 * Output: 6
12 * Explanation: The strings that can be formed are "cat" and "hat" so the answer is 3 + 3 = 6.
13 *
14 * Example 2:
15 *
16 * Input: words = ["hello","world","leetcode"], chars = "welldonehoneyr"
17 * Output: 10
18 * Explanation: The strings that can be formed are "hello" and "world" so the answer is 5 + 5 = 10.
19 *
20 *
21 * Constraints:
22 *
23 * 1 <= words.length <= 1000
24 * 1 <= words[i].length, chars.length <= 100
25 * words[i] and chars consist of lowercase English letters.
26 *
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/find-words-that-can-be-formed-by-characters/
31// discuss: https://leetcode.com/problems/find-words-that-can-be-formed-by-characters/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36 pub fn count_characters(words: Vec<String>, chars: String) -> i32 {
37 0
38 }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45 use super::*;
46
47 #[test]
48 fn test_1160() {
49 }
50}
51
Back
© 2025 bowen.ge All Rights Reserved.