Skip to content

Commit 97a9cfd

Browse files
committed
Added solution of problem 1544
1 parent 53412fc commit 97a9cfd

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/solutions/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ pub mod s1523_count_odd_numbers_in_an_interval_range;
325325
pub mod s1528_shuffle_string;
326326
pub mod s1534_count_good_triplets;
327327
pub mod s1539_kth_missing_positive_number;
328+
pub mod s1544_make_the_string_great;
328329
pub mod s1550_three_consecutive_odds;
329330
pub mod s1619_mean_of_array_after_removing_some_elements;
330331
pub mod s1935_maximum_number_of_words_you_can_type;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
pub fn make_good(s: String) -> String {
2+
s.chars()
3+
.fold(String::new(), |mut result, c_2| match (result.pop(), c_2) {
4+
(None, c_2) => c_2.to_string(),
5+
(Some(c_1), c_2) if c_1 != c_2 && c_1.to_lowercase().eq(c_2.to_lowercase()) => result,
6+
(Some(c_1), c_2) => result + &c_1.to_string() + &c_2.to_string(),
7+
})
8+
}
9+
10+
#[cfg(test)]
11+
mod test {
12+
use super::*;
13+
14+
#[test]
15+
fn test_case_1() {
16+
assert_eq!(make_good("leEeetcode".to_string()), "leetcode");
17+
}
18+
19+
#[test]
20+
fn test_case_2() {
21+
assert_eq!(make_good("abBAcC".to_string()), "");
22+
}
23+
24+
#[test]
25+
fn test_case_3() {
26+
assert_eq!(make_good("s".to_string()), "s");
27+
}
28+
}

0 commit comments

Comments
 (0)