diff --git a/algorithm/链表/removeElements.js b/algorithm/链表/removeElements.js index e69de29..f1eff38 100644 --- a/algorithm/链表/removeElements.js +++ b/algorithm/链表/removeElements.js @@ -0,0 +1,15 @@ +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 +}; +