From 40f97f89417e42742d1adb54e1a9e86e09e8ad7b Mon Sep 17 00:00:00 2001 From: SquidSpirit Date: Thu, 21 Aug 2025 00:11:42 +0800 Subject: [PATCH] feat: 1684_count_the_number_of_consistent_strings --- .../Cargo.lock | 7 ++++++ .../Cargo.toml | 6 +++++ .../src/lib.rs | 24 +++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 1684_count_the_number_of_consistent_strings/Cargo.lock create mode 100644 1684_count_the_number_of_consistent_strings/Cargo.toml create mode 100644 1684_count_the_number_of_consistent_strings/src/lib.rs 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 + } +}