feat: 1684_count_the_number_of_consistent_strings

This commit is contained in:
SquidSpirit 2025-08-21 00:11:42 +08:00
parent cbde308101
commit 40f97f8941
3 changed files with 37 additions and 0 deletions

View File

@ -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"

View File

@ -0,0 +1,6 @@
[package]
name = "count_the_number_of_consistent_strings"
version = "0.1.0"
edition = "2024"
[dependencies]

View File

@ -0,0 +1,24 @@
pub struct Solution;
impl Solution {
pub fn count_consistent_strings(allowed: String, words: Vec<String>) -> 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
}
}