File tree Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -239,6 +239,39 @@ function reversePrint(head: ListNode | null): number[] {
239
239
}
240
240
```
241
241
242
+ ### ** Rust**
243
+
244
+ ``` rust
245
+ // Definition for singly-linked list.
246
+ // #[derive(PartialEq, Eq, Clone, Debug)]
247
+ // pub struct ListNode {
248
+ // pub val: i32,
249
+ // pub next: Option<Box<ListNode>>
250
+ // }
251
+ //
252
+ // impl ListNode {
253
+ // #[inline]
254
+ // fn new(val: i32) -> Self {
255
+ // ListNode {
256
+ // next: None,
257
+ // val
258
+ // }
259
+ // }
260
+ // }
261
+ impl Solution {
262
+ pub fn reverse_print (head : Option <Box <ListNode >>) -> Vec <i32 > {
263
+ let mut arr : Vec <i32 > = vec! [];
264
+ let mut cur = head ;
265
+ while let Some (node ) = cur {
266
+ arr . push (node . val);
267
+ cur = node . next;
268
+ }
269
+ arr . reverse ();
270
+ arr
271
+ }
272
+ }
273
+ ```
274
+
242
275
### ** ...**
243
276
244
277
```
Original file line number Diff line number Diff line change
1
+ // Definition for singly-linked list.
2
+ // #[derive(PartialEq, Eq, Clone, Debug)]
3
+ // pub struct ListNode {
4
+ // pub val: i32,
5
+ // pub next: Option<Box<ListNode>>
6
+ // }
7
+ //
8
+ // impl ListNode {
9
+ // #[inline]
10
+ // fn new(val: i32) -> Self {
11
+ // ListNode {
12
+ // next: None,
13
+ // val
14
+ // }
15
+ // }
16
+ // }
17
+ impl Solution {
18
+ pub fn reverse_print ( head : Option < Box < ListNode > > ) -> Vec < i32 > {
19
+ let mut arr: Vec < i32 > = vec ! [ ] ;
20
+ let mut cur = head;
21
+ while let Some ( node) = cur {
22
+ arr. push ( node. val ) ;
23
+ cur = node. next ;
24
+ }
25
+ arr. reverse ( ) ;
26
+ arr
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments