正序记录到数组中,然后原地反转数组即可
func printListReversingly(head *ListNode) []int {
var h []int
for head != nil {
h = append(h, head.Val)
head = head.Next
}
for i, j:=0, len(h)-1; i<j; i, j = i+1, j-1 {
h[i], h[j] = h[j], h[i]
}
return h
}