main.go 327 B

12345678910111213141516171819202122232425
  1. package main
  2. func main() {
  3. }
  4. type ListNode struct {
  5. Val int
  6. Next *ListNode
  7. }
  8. func reversePrint(head *ListNode) []int {
  9. var tmpArr []int
  10. for head != nil {
  11. tmpArr = append(tmpArr, head.Val)
  12. head = head.Next
  13. }
  14. var ret []int
  15. for i := len(tmpArr) - 1; i >= 0; i-- {
  16. ret = append(ret, tmpArr[i])
  17. }
  18. return ret
  19. }