File tree 1 file changed +42
-0
lines changed
1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -241,6 +241,8 @@ function reversePrint(head: ListNode | null): number[] {
241
241
242
242
### ** Rust**
243
243
244
+ - 动态数组
245
+
244
246
``` rust
245
247
// Definition for singly-linked list.
246
248
// #[derive(PartialEq, Eq, Clone, Debug)]
@@ -272,6 +274,46 @@ impl Solution {
272
274
}
273
275
```
274
276
277
+ - 遍历
278
+
279
+ ``` rust
280
+ // Definition for singly-linked list.
281
+ // #[derive(PartialEq, Eq, Clone, Debug)]
282
+ // pub struct ListNode {
283
+ // pub val: i32,
284
+ // pub next: Option<Box<ListNode>>
285
+ // }
286
+ //
287
+ // impl ListNode {
288
+ // #[inline]
289
+ // fn new(val: i32) -> Self {
290
+ // ListNode {
291
+ // next: None,
292
+ // val
293
+ // }
294
+ // }
295
+ // }
296
+ impl Solution {
297
+ pub fn reverse_print (head : Option <Box <ListNode >>) -> Vec <i32 > {
298
+ let mut cur = & head ;
299
+ let mut n = 0 ;
300
+ while let Some (node ) = cur {
301
+ cur = & node . next;
302
+ n += 1 ;
303
+ }
304
+
305
+ let mut arr = vec! [0 ; n ];
306
+ let mut cur = head ;
307
+ while let Some (node ) = cur {
308
+ n -= 1 ;
309
+ arr [n ] = node . val;
310
+ cur = node . next;
311
+ }
312
+ arr
313
+ }
314
+ }
315
+ ```
316
+
275
317
### ** ...**
276
318
277
319
```
You can’t perform that action at this time.
0 commit comments