-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathlib.rs
39 lines (32 loc) · 906 Bytes
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
struct Solution;
impl Solution {
pub fn make_good(s: String) -> String {
let mut stack: Vec<u8> = Vec::new();
for ch in s.as_bytes() {
match stack.last() {
Some(c) => match ch + 32 == *c || *ch == c + 32 {
true => {
stack.pop();
}
false => stack.push(*ch),
},
None => stack.push(*ch),
}
}
String::from_utf8_lossy(&stack).to_string()
}
}
#[test]
fn it_works() {
let result = 2 + 2;
assert_eq!(result, 4);
assert_eq!(
Solution::make_good(String::from("leEeetcode")),
String::from("leetcode")
);
assert_eq!(
Solution::make_good(String::from("abBAcC")),
String::from("")
);
assert_eq!(Solution::make_good(String::from("Pp")), String::from(""));
}