feat: 1935_maximum_number_of_words_you_can_type
This commit is contained in:
parent
d5e093754a
commit
d5c099d9b3
7
1935_maximum_number_of_words_you_can_type/Cargo.lock
generated
Normal file
7
1935_maximum_number_of_words_you_can_type/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 = "maximum_number_of_words_you_can_type"
|
||||||
|
version = "0.1.0"
|
6
1935_maximum_number_of_words_you_can_type/Cargo.toml
Normal file
6
1935_maximum_number_of_words_you_can_type/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "maximum_number_of_words_you_can_type"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
30
1935_maximum_number_of_words_you_can_type/src/lib.rs
Normal file
30
1935_maximum_number_of_words_you_can_type/src/lib.rs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn can_be_typed_words(mut text: String, broken_letters: String) -> i32 {
|
||||||
|
text.push(' ');
|
||||||
|
|
||||||
|
let broken_set = std::collections::HashSet::<char>::from_iter(broken_letters.chars());
|
||||||
|
let mut broken_flag = false;
|
||||||
|
|
||||||
|
let mut count = 0;
|
||||||
|
for c in text.chars() {
|
||||||
|
if c == ' ' {
|
||||||
|
if !broken_flag {
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
broken_flag = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if broken_flag {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if broken_set.contains(&c) {
|
||||||
|
broken_flag = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
count
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user