| package main | |
| type ListNode struct { | |
| Val int | |
| Next *ListNode | |
| } | |
| func reversePrint(head *ListNode) []int { | |
| var res []int | |
| for head != nil { | |
| res = append(res, head.Val) | |
| head = head.Next | |
| } | |
| for i, j := 0, len(res)-1; i < j; i, j = i+1, j-1 { | |
| res[i], res[j] = res[j], res[i] | |
| } | |
| return res | |
| } | |