Skip to content

Instantly share code, notes, and snippets.

@zhoufenfens
Created May 18, 2020 17:09
Show Gist options
  • Save zhoufenfens/c9f16969d54d49334159500c8015827b to your computer and use it in GitHub Desktop.
Save zhoufenfens/c9f16969d54d49334159500c8015827b to your computer and use it in GitHub Desktop.
var removeNthFromEnd = function(head, n) {
let target = head,
cur = head;
while (n--) {
cur = cur.next;
}
while (cur && cur.next) {
cur = cur.next;
target = target.next;
}
if (!cur) return head.next;
target.next = target.next.next;
return head;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment