![Go语言实现:【剑指offer】从尾到头打印链表 Go语言实现:【剑指offer】从尾到头打印链表](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
该题目来源于牛客网《剑指offer》专题。
输入一个链表,按链表从尾到头的顺序返回一个ArrayList。
Go语言实现:
type ListNode struct {
Val int
Next *ListNode
}
func fmtListNode(head *ListNode) {
l := list.New()
for ; head != nil; head = head.Next {
l.PushFront(head.Val)
}
for item := l.Front(); item != nil; item = item.Next() {
fmt.Println(item.Value)
}
}