Skip to content

Commit b88fe76

Browse files
committed
solve(3174): implement solution with stack
1 parent 9ec1660 commit b88fe76

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/solutions/_3174_clear_digits.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use crate::solutions::Solution;
2+
3+
impl Solution {
4+
pub fn clear_digits(s: String) -> String {
5+
let mut stack = String::new();
6+
7+
for c in s.chars() {
8+
if c.is_ascii_digit() {
9+
stack.pop();
10+
} else {
11+
stack.push(c);
12+
}
13+
}
14+
15+
stack
16+
}
17+
}
18+
19+
#[test]
20+
fn test() {
21+
assert_eq!(Solution::clear_digits("abc".to_owned()), "abc");
22+
assert_eq!(Solution::clear_digits("cb34".to_owned()), "");
23+
}

src/solutions/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ pub mod _0026_remove_duplicates_from_sorted_array;
55
pub mod _0027_remove_element;
66
pub mod _1848_minimum_distance_to_the_target_element;
77
pub mod _3046_split_the_array;
8+
pub mod _3174_clear_digits;
89

910
pub struct Solution {}

0 commit comments

Comments
 (0)