Skip to content

Commit 34a2bc8

Browse files
committed
203
1 parent 4901165 commit 34a2bc8

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Diff for: 203.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* function ListNode(val) {
4+
* this.val = val;
5+
* this.next = null;
6+
* }
7+
*/
8+
/**
9+
* @param {ListNode} head
10+
* @param {number} val
11+
* @return {ListNode}
12+
*/
13+
var removeElements = function(head, val) {
14+
while(head !== null){
15+
if(head.val !== val) break;
16+
head = head.next;
17+
}
18+
if(head === null) return head;
19+
var temp = head;
20+
while(temp.next !== null){
21+
if(temp.next.val === val){
22+
temp.next = temp.next.next;
23+
}else{
24+
temp = temp.next;
25+
}
26+
}
27+
return head;
28+
};

0 commit comments

Comments
 (0)