feat: 1684_count_the_number_of_consistent_strings
This commit is contained in:
parent
cbde308101
commit
40f97f8941
7
1684_count_the_number_of_consistent_strings/Cargo.lock
generated
Normal file
7
1684_count_the_number_of_consistent_strings/Cargo.lock
generated
Normal 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"
|
6
1684_count_the_number_of_consistent_strings/Cargo.toml
Normal file
6
1684_count_the_number_of_consistent_strings/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "count_the_number_of_consistent_strings"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
24
1684_count_the_number_of_consistent_strings/src/lib.rs
Normal file
24
1684_count_the_number_of_consistent_strings/src/lib.rs
Normal 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
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user