题解 | #从尾到头打印链表#
从尾到头打印链表
http://www.nowcoder.com/practice/d0267f7f55b3412ba93bd35cfa8e8035
GO语言的递归写法
package main import . "nc_tools" /* * type ListNode struct{ * Val int * Next *ListNode * } */ /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param head ListNode类 * @return int整型一维数组 */ func printListFromTailToHead( head *ListNode ) []int { // write code here var ans []int if head == nil{ return ans } ans = printListFromTailToHead(head.Next) ans = append(ans, head.Val) return ans }