# 面试：从尾到头打印链表

输入：head = [1,3,2]

0 <= 链表长度 <= 10000

#### 题解1：递归法

/**
* type ListNode struct {
*     Val int
*     Next *ListNode
* }
*/
return nil
}

}

return list
}

}

/**
* type ListNode struct {
*     Val int
*     Next *ListNode
* }
*/
return []int{}
}

}

#### 题解2：反转链表

/**
* type ListNode struct {
*     Val int
*     Next *ListNode
* }
*/
return nil
}

res := []int{}
}

}

return res
}

#### 解法3：反转数组

/**
* type ListNode struct {
*     Val int
*     Next *ListNode
* }
*/
return nil
}

res := []int{}
}

for i, j := 0, len(res)-1; i < j; {
res[i], res[j] = res[j], res[i]
i++
j--
}

return res
}

#### 解法4：栈

/**
* type ListNode struct {
*     Val int
*     Next *ListNode
* }
*/
import "container/list"

return nil
}

res := list.New()
}

ret := []int{}
for e := res.Front(); e != nil; e = e.Next() {
ret = append(ret, e.Value.(int))
}

return ret
}

#### 解法5：遍历两次

/**
* type ListNode struct {
*     Val int
*     Next *ListNode
* }
*/
return nil
}

count := 0
count++
}

res := make([]int, count)
i := 0
i++
}

return res
}