File tree 3 files changed +73
-0
lines changed
solution/2600-2699/2696.Minimum String Length After Removing Substrings
3 files changed +73
-0
lines changed Original file line number Diff line number Diff line change @@ -149,6 +149,32 @@ function minLength(s: string): number {
149
149
}
150
150
```
151
151
152
+ ### ** Rust**
153
+
154
+ ``` rust
155
+ impl Solution {
156
+ pub fn min_length (s : String ) -> i32 {
157
+ let mut ans : Vec <u8 > = Vec :: new ();
158
+
159
+ for c in s . bytes () {
160
+ if let Some (last ) = ans . last () {
161
+ if * last == b 'A' && c == b 'B' {
162
+ ans . pop ();
163
+ } else if * last == b 'C' && c == b 'D' {
164
+ ans . pop ();
165
+ } else {
166
+ ans . push (c );
167
+ }
168
+ } else {
169
+ ans . push (c );
170
+ }
171
+ }
172
+
173
+ ans . len () as i32
174
+ }
175
+ }
176
+ ```
177
+
152
178
### ** ...**
153
179
154
180
```
Original file line number Diff line number Diff line change @@ -131,6 +131,32 @@ function minLength(s: string): number {
131
131
}
132
132
```
133
133
134
+ ### ** Rust**
135
+
136
+ ``` rust
137
+ impl Solution {
138
+ pub fn min_length (s : String ) -> i32 {
139
+ let mut ans : Vec <u8 > = Vec :: new ();
140
+
141
+ for c in s . bytes () {
142
+ if let Some (last ) = ans . last () {
143
+ if * last == b 'A' && c == b 'B' {
144
+ ans . pop ();
145
+ } else if * last == b 'C' && c == b 'D' {
146
+ ans . pop ();
147
+ } else {
148
+ ans . push (c );
149
+ }
150
+ } else {
151
+ ans . push (c );
152
+ }
153
+ }
154
+
155
+ ans . len () as i32
156
+ }
157
+ }
158
+ ```
159
+
134
160
### ** ...**
135
161
136
162
```
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn min_length ( s : String ) -> i32 {
3
+ let mut ans: Vec < u8 > = Vec :: new ( ) ;
4
+
5
+ for c in s. bytes ( ) {
6
+ if let Some ( last) = ans. last ( ) {
7
+ if * last == b'A' && c == b'B' {
8
+ ans. pop ( ) ;
9
+ } else if * last == b'C' && c == b'D' {
10
+ ans. pop ( ) ;
11
+ } else {
12
+ ans. push ( c) ;
13
+ }
14
+ } else {
15
+ ans. push ( c) ;
16
+ }
17
+ }
18
+
19
+ ans. len ( ) as i32
20
+ }
21
+ }
You can’t perform that action at this time.
0 commit comments