MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / make_good

Function make_good

1544-make-the-string-great.rs:1–20  ·  view source on GitHub ↗
(s: String)

Source from the content-addressed store, hash-verified

1pub fn make_good(s: String) -> String {
2 if s.len() == 1 { return s }
3 let mut s = s.clone();
4 'outer: loop {
5 if s.len() == 1 { return s }
6 for i in 0..s.len() - 2 {
7 if (s.chars().nth(i).unwrap() as i32 - s.chars().nth(i+1).unwrap() as i32).abs() == 32 {
8 s.remove(i);
9 s.remove(i);
10 continue 'outer;
11 }
12 }
13 break;
14 }
15 if (s.chars().nth(s.len()-1).unwrap() as i32 - s.chars().nth(s.len()-2).unwrap() as i32).abs() == 32 {
16 s.remove(s.len()-1);
17 s.remove(s.len()-1);
18 }
19 s
20}
21
22fn main() {
23 println!("{:?}", make_good("leEeetcode".to_string()));

Callers

nothing calls this directly

Calls 1

removeMethod · 0.45

Tested by

no test coverage detected