diff --git a/1684_count_the_number_of_consistent_strings/Cargo.lock b/1684_count_the_number_of_consistent_strings/Cargo.lock new file mode 100644 index 0000000..b0bf651 --- /dev/null +++ b/1684_count_the_number_of_consistent_strings/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "count_the_number_of_consistent_strings" +version = "0.1.0" diff --git a/1684_count_the_number_of_consistent_strings/Cargo.toml b/1684_count_the_number_of_consistent_strings/Cargo.toml new file mode 100644 index 0000000..2fcb246 --- /dev/null +++ b/1684_count_the_number_of_consistent_strings/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "count_the_number_of_consistent_strings" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/1684_count_the_number_of_consistent_strings/src/lib.rs b/1684_count_the_number_of_consistent_strings/src/lib.rs new file mode 100644 index 0000000..4dd4a13 --- /dev/null +++ b/1684_count_the_number_of_consistent_strings/src/lib.rs @@ -0,0 +1,24 @@ +pub struct Solution; + +impl Solution { + pub fn count_consistent_strings(allowed: String, words: Vec) -> i32 { + let mut allowed_table = 0u32; + for c in allowed.chars() { + allowed_table |= 1 << c as u32 - 97; + } + + let mut result = 0; + for word in words { + let mut is_subset = 1; + for c in word.chars() { + if allowed_table & 1 << c as u32 - 97 == 0 { + is_subset = 0; + break; + } + } + result += is_subset; + } + + result + } +}