Created
July 20, 2020 07:05
-
-
Save RP-3/5baa031e5b2402a6f4b829cfebd3a9a7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Definition for singly-linked list. | |
* function ListNode(val, next) { | |
* this.val = (val===undefined ? 0 : val) | |
* this.next = (next===undefined ? null : next) | |
* } | |
*/ | |
/** | |
* @param {ListNode} head | |
* @param {number} val | |
* @return {ListNode} | |
*/ | |
var removeElements = function(head, val) { | |
const dummy = { next: head }; | |
let [prev, curr] = [dummy, head]; | |
while(curr){ | |
if(curr.val === val) prev.next = curr.next; | |
else prev = curr; | |
curr = curr.next; | |
} | |
return dummy.next; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment