20240914 finished.
This commit is contained in:
parent
c3c48fae30
commit
d38a174ec2
|
@ -235,3 +235,4 @@ 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;
|
||||
mod p2390_removing_stars_from_a_string;
|
41
src/problem/p2390_removing_stars_from_a_string.rs
Normal file
41
src/problem/p2390_removing_stars_from_a_string.rs
Normal file
|
@ -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<char> = 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()));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user