From d38a174ec2830357cb769c9035deff2a693b3d11 Mon Sep 17 00:00:00 2001 From: jackfiled Date: Sat, 14 Sep 2024 11:46:11 +0800 Subject: [PATCH] 20240914 finished. --- src/problem/mod.rs | 3 +- .../p2390_removing_stars_from_a_string.rs | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/problem/p2390_removing_stars_from_a_string.rs diff --git a/src/problem/mod.rs b/src/problem/mod.rs index 31efaf0..0008c50 100644 --- a/src/problem/mod.rs +++ b/src/problem/mod.rs @@ -234,4 +234,5 @@ mod p2181_merge_nodes_in_between_zeros; mod p2552_count_increasing_quadruplets; mod p2555_maximize_win_from_two_segments; mod p2576_find_the_maximum_number_of_marked_indices; -mod p2398_maximum_number_of_robots_within_budget; \ No newline at end of file +mod p2398_maximum_number_of_robots_within_budget; +mod p2390_removing_stars_from_a_string; \ No newline at end of file diff --git a/src/problem/p2390_removing_stars_from_a_string.rs b/src/problem/p2390_removing_stars_from_a_string.rs new file mode 100644 index 0000000..1a87335 --- /dev/null +++ b/src/problem/p2390_removing_stars_from_a_string.rs @@ -0,0 +1,41 @@ +/** + * [2390] Removing Stars From a String + */ +pub struct Solution {} + + +// submission codes start here + +impl Solution { + pub fn remove_stars(s: String) -> String { + let s : Vec = s.chars().collect(); + + let mut result = Vec::with_capacity(s.len()); + + for i in s { + match i { + '*' => { + result.pop(); + } + _ => { + result.push(i); + } + } + } + + result.iter().collect() + } +} + +// submission codes end + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_2390() { + assert_eq!("lecoe".to_owned(), Solution::remove_stars("leet**cod*e".to_owned())); + assert_eq!("".to_owned(), Solution::remove_stars("erase*****".to_owned())); + } +}