面试题06. 从尾到头打印链表

难度: 简单




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
func reversePrint(head *ListNode) []int {

res := make([]int,0)

if head == nil {
return res
}

temp := reversePrint(head.Next)
res = append(res,temp...)

res = append(res,head.Val)
return res

}