JZ15 反转链表
题目描述
输入一个链表,反转链表后,输出新链表的表头。
func ReverseList( head *ListNode ) *ListNode { // write code here if head == nil || head.Next == nil { return head } var pre, cur, post *ListNode = nil, head, head.Next for cur != nil { post = cur.Next cur.Next = pre pre = cur cur = post } return pre }