diff --git a/leetcode/1786-count-the-number-of-consistent-strings/solution.rs b/leetcode/1786-count-the-number-of-consistent-strings/solution.rs new file mode 100644 index 0000000..3fa130e --- /dev/null +++ b/leetcode/1786-count-the-number-of-consistent-strings/solution.rs @@ -0,0 +1,8 @@ +impl Solution { + pub fn count_consistent_strings(allowed: String, words: Vec) -> i32 { + let allowed: std::collections::HashSet<_> = allowed.chars().collect(); + words.iter() + .filter(|w| w.chars().all(|c| allowed.contains(&c))) + .count() as i32 + } +}