File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ pub 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
+
22
+ fn main ( ) {
23
+ println ! ( "{:?}" , make_good( "leEeetcode" . to_string( ) ) ) ;
24
+ println ! ( "{:?}" , make_good( "abBAcC" . to_string( ) ) ) ;
25
+ println ! ( "{:?}" , make_good( "A" . to_string( ) ) ) ;
26
+ println ! ( "{:?}" , make_good( "Aa" . to_string( ) ) ) ;
27
+ println ! ( "{:?}" , make_good( "asLwGWlSAQq" . to_string( ) ) ) ;
28
+ println ! ( "{:?}" , make_good( "XxDFOBKRrkbofdXxeEijJIcCsBikPgfxXFGpKIbSemGivrqqQQRVIgMEPBWpPwbpSCWqWQqwQwcsQqasLwGWlSAQq" . to_string( ) ) ) ;
29
+ // println!("{:?}", ('b' as i32 -'B' as i32).abs()); // 32
30
+ }
You can’t perform that action at this time.
0 commit comments