203. Remove Linked List Elements
202410082159
tags: #linked-list
var removeElements = function(head, val) {
const dummy = new ListNode();
dummy.next = head;
let cur = dummy;
while (cur.next !== null) {
if (cur.next.val === val) {
cur.next = cur.next.next;
} else {
cur = cur.next;
}
}
return dummy.next;
};