all-of-frontend/algorithm/链表/removeElements.js
2021-04-14 07:54:05 +08:00

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
};