题解 | #删除链表的倒数第n个节点#
删除链表的倒数第n个节点
http://www.nowcoder.com/practice/f95dcdafbde44b22a6d741baf71653f6
package main import . "nc_tools" func removeNthFromEnd( head *ListNode , n int ) *ListNode { // write code here dummy := &ListNode{Next: head} fast, slow := head, dummy for i := 0; i < n; i++ { fast = fast.Next } for fast != nil { fast = fast.Next slow = slow.Next } slow.Next = slow.Next.Next return dummy.Next }