leetcode 19. Remove Nth Node From End of List
删掉最后第n个节点。
图解如下:
var removeNthFromEnd = function(head, n) {
var dummy = new ListNode;
dummy.next = head;
var fast = dummy, slow = dummy, goSlow = false
while(fast.next){
if(goSlow){
slow = slow.next
}
fast = fast.next
n--
if(n == 0){
goSlow = true
}
}
if(slow.next){
slow.next = slow.next.next
}
return dummy.next
};
机器瞎学/数据掩埋/模式混淆/人工智障/深度遗忘/神经掉线/计算机幻觉/专注单身二十五年