题解 | #反转链表#
反转链表
http://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca
package main import . "nc_tools" //递归 func ReverseList(head *ListNode) *ListNode { if head == nil || head.Next == nil { return head } res := ReverseList(head.Next) head.Next.Next = head head.Next = nil return res } // //迭代 // func ReverseList(head *ListNode) *ListNode { // var prev *ListNode // cur := head // for cur != nil { // temp := cur.Next // cur.Next = prev // prev = cur // cur = temp // } // return prev // }