1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| // @Title: 从尾到头打印链表 (从尾到头打印链表 LCOF)
// @Author: 15816537946@163.com
// @Date: 2022-02-02 10:23:26
// @Runtime: 0 ms
// @Memory: 2.4 MB
impl Solution {
pub fn reverse_print(mut head: Option<Box<ListNode>>) -> Vec<i32> {
let mut res = Vec::new();
loop {
match head {
Some(v) => {
res.push(v.val);
head = v.next;
}
None => break,
}
}
res.reverse();
res
}
}
|