File tree 3 files changed +76
-0
lines changed
solution/0900-0999/0969.Pancake Sorting
3 files changed +76
-0
lines changed Original file line number Diff line number Diff line change @@ -205,6 +205,33 @@ func pancakeSort(arr []int) []int {
205
205
}
206
206
```
207
207
208
+ ### ** Rust**
209
+
210
+ ``` rust
211
+ impl Solution {
212
+ pub fn pancake_sort (mut arr : Vec <i32 >) -> Vec <i32 > {
213
+ let mut res = vec! [];
214
+ for n in (1 .. arr . len ()). rev () {
215
+ let mut max_idx = 0 ;
216
+ for idx in 0 ..= n {
217
+ if arr [max_idx ] < arr [idx ] {
218
+ max_idx = idx ;
219
+ }
220
+ }
221
+ if max_idx != n {
222
+ if max_idx != 0 {
223
+ arr [..= max_idx ]. reverse ();
224
+ res . push (max_idx as i32 + 1 );
225
+ }
226
+ arr [..= n ]. reverse ();
227
+ res . push (n as i32 + 1 );
228
+ }
229
+ }
230
+ res
231
+ }
232
+ }
233
+ ```
234
+
208
235
### ** ...**
209
236
210
237
```
Original file line number Diff line number Diff line change @@ -194,6 +194,33 @@ func pancakeSort(arr []int) []int {
194
194
}
195
195
```
196
196
197
+ ### ** Rust**
198
+
199
+ ``` rust
200
+ impl Solution {
201
+ pub fn pancake_sort (mut arr : Vec <i32 >) -> Vec <i32 > {
202
+ let mut res = vec! [];
203
+ for n in (1 .. arr . len ()). rev () {
204
+ let mut max_idx = 0 ;
205
+ for idx in 0 ..= n {
206
+ if arr [max_idx ] < arr [idx ] {
207
+ max_idx = idx ;
208
+ }
209
+ }
210
+ if max_idx != n {
211
+ if max_idx != 0 {
212
+ arr [..= max_idx ]. reverse ();
213
+ res . push (max_idx as i32 + 1 );
214
+ }
215
+ arr [..= n ]. reverse ();
216
+ res . push (n as i32 + 1 );
217
+ }
218
+ }
219
+ res
220
+ }
221
+ }
222
+ ```
223
+
197
224
### ** ...**
198
225
199
226
```
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn pancake_sort ( mut arr : Vec < i32 > ) -> Vec < i32 > {
3
+ let mut res = vec ! [ ] ;
4
+ for n in ( 1 ..arr. len ( ) ) . rev ( ) {
5
+ let mut max_idx = 0 ;
6
+ for idx in 0 ..=n {
7
+ if arr[ max_idx] < arr[ idx] {
8
+ max_idx = idx;
9
+ }
10
+ }
11
+ if max_idx != n {
12
+ if max_idx != 0 {
13
+ arr[ ..=max_idx] . reverse ( ) ;
14
+ res. push ( max_idx as i32 + 1 ) ;
15
+ }
16
+ arr[ ..=n] . reverse ( ) ;
17
+ res. push ( n as i32 + 1 ) ;
18
+ }
19
+ }
20
+ res
21
+ }
22
+ }
You can’t perform that action at this time.
0 commit comments