20240927 finished.
This commit is contained in:
parent
8830b0dbcd
commit
c3c8684d5e
|
@ -246,4 +246,5 @@ mod p2374_node_with_highest_edge_score;
|
||||||
mod p997_find_the_town_judge;
|
mod p997_find_the_town_judge;
|
||||||
mod p2207_maximize_number_of_subsequences_in_a_string;
|
mod p2207_maximize_number_of_subsequences_in_a_string;
|
||||||
mod p2306_naming_a_company;
|
mod p2306_naming_a_company;
|
||||||
mod p2535_difference_between_element_sum_and_digit_sum_of_an_array;
|
mod p2535_difference_between_element_sum_and_digit_sum_of_an_array;
|
||||||
|
mod p2516_take_k_of_each_character_from_left_and_right;
|
|
@ -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<char> = 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() {
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user