1684. Count the Number of Consistent Strings Easy

@problem@discussion
#Array#Hash Table#String#Bit Manipulation



1/**
2 * [1684] Count the Number of Consistent Strings
3 *
4 * You are given a string allowed consisting of distinct characters and an array of strings words. A string is consistent if all characters in the string appear in the string allowed.
5 * Return the number of consistent strings in the array words.
6 *  
7 * Example 1:
8 * 
9 * Input: allowed = "ab", words = ["ad","bd","aaab","baa","badab"]
10 * Output: 2
11 * Explanation: Strings "aaab" and "baa" are consistent since they only contain characters 'a' and 'b'.
12 * 
13 * Example 2:
14 * 
15 * Input: allowed = "abc", words = ["a","b","c","ab","ac","bc","abc"]
16 * Output: 7
17 * Explanation: All strings are consistent.
18 * 
19 * Example 3:
20 * 
21 * Input: allowed = "cad", words = ["cc","acd","b","ba","bac","bad","ac","d"]
22 * Output: 4
23 * Explanation: Strings "cc", "acd", "ac", and "d" are consistent.
24 * 
25 *  
26 * Constraints:
27 * 
28 * 	1 <= words.length <= 10^4
29 * 	1 <= allowed.length <=^ 26
30 * 	1 <= words[i].length <= 10
31 * 	The characters in allowed are distinct.
32 * 	words[i] and allowed contain only lowercase English letters.
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/count-the-number-of-consistent-strings/
38// discuss: https://leetcode.com/problems/count-the-number-of-consistent-strings/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn count_consistent_strings(allowed: String, words: Vec<String>) -> i32 {
44        0
45    }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_1684() {
56    }
57}
58


Back
© 2025 bowen.ge All Rights Reserved.