Created
May 18, 2020 17:09
-
-
Save zhoufenfens/c9f16969d54d49334159500c8015827b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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