Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3cfb9a5 commit 163f2e6Copy full SHA for 163f2e6
javascript/203-remove-linked-list-elements.js
@@ -0,0 +1,27 @@
1
+// problem link https://leetcode.com/problems/remove-linked-list-elements/
2
+// time complexity O(n).
3
+
4
+var removeElements = function(head, val) {
5
+ // let currunt = head;
6
+ let pre = new ListNode(null, head);
7
+ let dummy = pre;
8
+ while(head) {
9
+ if(head.val == val) {
10
+ while(head && head.val == val) {
11
+ head = head.next;
12
+ }
13
+ pre.next = head;
14
+ pre = head;
15
+ if(head) {
16
+ temp = head;
17
18
+ temp = null;
19
20
+ continue;
21
22
+ pre = pre.next;
23
24
25
26
+ return dummy.next;
27
+};
0 commit comments