Skip to content

Commit 169b271

Browse files
committed
update 203. 移除链表元素
1 parent bc56200 commit 169b271

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

algorithms/remove-linked-list-elements.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,21 @@ var removeElements = function (head, val) {
2323
}
2424
return curr;
2525

26-
// 2. 迭代
26+
// 2. 迭代 (dummy node)
2727

2828
// let curr = head;
29-
// let prev = null;
29+
// let dummyNode = new ListNode(-1);
30+
// dummyNode.next = head;
31+
// let prev = dummyNode;
3032

3133
// while (curr) {
3234
// if (curr.val === val) {
33-
// if (curr === head) {
34-
// head = head.next;
35-
// } else {
36-
// prev.next = curr.next;
37-
// }
35+
// prev.next = curr.next;
3836
// } else {
3937
// prev = curr;
4038
// }
4139
// curr = curr.next;
4240
// }
4341

44-
// return head;
42+
// return dummyNode.next;
4543
};

0 commit comments

Comments
 (0)