From 70516c9818c19bd68a546c2f7743056bfae398ff Mon Sep 17 00:00:00 2001 From: xuwu Date: Wed, 14 Apr 2021 07:54:05 +0800 Subject: [PATCH] feat: removeElements --- algorithm/链表/removeElements.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 +}; +