Sunny-117 / js-challenges

✨✨✨ Challenge your JavaScript programming limits step by step

Home Page:https://juejin.cn/column/7244788137410560055

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

删除链表的倒数第 N 个结点

Sunny-117 opened this issue · comments

commented
var removeNthFromEnd = function(head, n) {
    if(!head) return head
    let ret = new ListNode(null, head), p = ret, q = head
    while(n--) q = q.next
    while(q) q = q.next, p = p.next
    p.next = p.next.next

    return ret.next

};