File tree Expand file tree Collapse file tree 3 files changed +73
-0
lines changed
solution/0300-0399/0345.Reverse Vowels of a String Expand file tree Collapse file tree 3 files changed +73
-0
lines changed Original file line number Diff line number Diff line change @@ -175,6 +175,32 @@ function reverseVowels(s: string): string {
175
175
}
176
176
```
177
177
178
+ ### ** Rust**
179
+
180
+ ``` rust
181
+ impl Solution {
182
+ pub fn reverse_vowels (s : String ) -> String {
183
+ let vowel = String :: from (" aeiouAEIOU" );
184
+ let mut data : Vec <char > = s . chars (). collect ();
185
+ let (mut i , mut j ) = (0 , s . len () - 1 );
186
+ while i < j {
187
+ while i < j && ! vowel . contains (data [i ]) {
188
+ i += 1 ;
189
+ }
190
+ while i < j && ! vowel . contains (data [j ]) {
191
+ j -= 1 ;
192
+ }
193
+ if i < j {
194
+ data . swap (i , j );
195
+ i += 1 ;
196
+ j -= 1 ;
197
+ }
198
+ }
199
+ data . iter (). collect ()
200
+ }
201
+ }
202
+ ```
203
+
178
204
### ** ...**
179
205
180
206
```
Original file line number Diff line number Diff line change @@ -151,6 +151,32 @@ function reverseVowels(s: string): string {
151
151
}
152
152
```
153
153
154
+ ### ** Rust**
155
+
156
+ ``` rust
157
+ impl Solution {
158
+ pub fn reverse_vowels (s : String ) -> String {
159
+ let vowel = String :: from (" aeiouAEIOU" );
160
+ let mut data : Vec <char > = s . chars (). collect ();
161
+ let (mut i , mut j ) = (0 , s . len () - 1 );
162
+ while i < j {
163
+ while i < j && ! vowel . contains (data [i ]) {
164
+ i += 1 ;
165
+ }
166
+ while i < j && ! vowel . contains (data [j ]) {
167
+ j -= 1 ;
168
+ }
169
+ if i < j {
170
+ data . swap (i , j );
171
+ i += 1 ;
172
+ j -= 1 ;
173
+ }
174
+ }
175
+ data . iter (). collect ()
176
+ }
177
+ }
178
+ ```
179
+
154
180
### ** ...**
155
181
156
182
```
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn reverse_vowels ( s : String ) -> String {
3
+ let vowel = String :: from ( "aeiouAEIOU" ) ;
4
+ let mut data: Vec < char > = s. chars ( ) . collect ( ) ;
5
+ let ( mut i, mut j) = ( 0 , s. len ( ) - 1 ) ;
6
+ while i < j {
7
+ while i < j && !vowel. contains ( data[ i] ) {
8
+ i += 1 ;
9
+ }
10
+ while i < j && !vowel. contains ( data[ j] ) {
11
+ j -= 1 ;
12
+ }
13
+ if i < j {
14
+ data. swap ( i, j) ;
15
+ i += 1 ;
16
+ j -= 1 ;
17
+ }
18
+ }
19
+ data. iter ( ) . collect ( )
20
+ }
21
+ }
You can’t perform that action at this time.
0 commit comments