feat: 1935_maximum_number_of_words_you_can_type

This commit is contained in:
SquidSpirit 2025-09-16 01:16:21 +08:00
parent d5e093754a
commit d5c099d9b3
3 changed files with 43 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 = "maximum_number_of_words_you_can_type"
version = "0.1.0"

View File

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

View 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
}
}