mirror of
https://github.com/KieSun/all-of-frontend.git
synced 2024-11-13 18:38:15 +08:00
16 lines
313 B
JavaScript
16 lines
313 B
JavaScript
var removeElements = function(head, val) {
|
|
const dummy = new ListNode()
|
|
let node = dummy
|
|
while (head) {
|
|
const tmp = head.next
|
|
if (head.val !== val) {
|
|
node.next = head
|
|
node = head
|
|
}
|
|
head = tmp
|
|
}
|
|
node.next = null
|
|
return dummy.next
|
|
};
|
|
|