From c3c8684d5eb254c7ce5d722974747ed06b1063ca Mon Sep 17 00:00:00 2001 From: jackfiled Date: Fri, 27 Sep 2024 23:06:14 +0800 Subject: [PATCH] 20240927 finished. --- src/problem/mod.rs | 3 +- ...k_of_each_character_from_left_and_right.rs | 54 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/problem/p2516_take_k_of_each_character_from_left_and_right.rs diff --git a/src/problem/mod.rs b/src/problem/mod.rs index 4b27568..1277db5 100644 --- a/src/problem/mod.rs +++ b/src/problem/mod.rs @@ -246,4 +246,5 @@ mod p2374_node_with_highest_edge_score; mod p997_find_the_town_judge; mod p2207_maximize_number_of_subsequences_in_a_string; mod p2306_naming_a_company; -mod p2535_difference_between_element_sum_and_digit_sum_of_an_array; \ No newline at end of file +mod p2535_difference_between_element_sum_and_digit_sum_of_an_array; +mod p2516_take_k_of_each_character_from_left_and_right; \ No newline at end of file diff --git a/src/problem/p2516_take_k_of_each_character_from_left_and_right.rs b/src/problem/p2516_take_k_of_each_character_from_left_and_right.rs new file mode 100644 index 0000000..5419bce --- /dev/null +++ b/src/problem/p2516_take_k_of_each_character_from_left_and_right.rs @@ -0,0 +1,54 @@ +/** + * [2516] Take K of Each Character From Left and Right + */ +pub struct Solution {} + + +// submission codes start here + +impl Solution { + pub fn take_characters(s: String, k: i32) -> i32 { + let s: Vec = s.chars().collect(); + let n = s.len(); + + let mut left_counts = vec![0; 3]; + + for &c in s.iter() { + match c { + 'a' => left_counts[0] += 1, + 'b' => left_counts[1] += 1, + 'c' => left_counts[2] += 1, + _ => unreachable!(), + } + } + + if left_counts.iter().any(|x| *x < k) { + return -1; + } + + let mut result = 0; + let mut right = 0; + let mut right_counts = vec![0;3]; + + // 左指针从右往左移动 + for left in (0..n - 1).rev() { + + } + + + + + result + } +} + +// submission codes end + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_2516() { + } +}