1
class Solution {
2
public ListNode removeElements(ListNode head, int val) {
3
if (head == null) {
4
return head;
5
}
6
ListNode result = head;
7
while (head.next != null) {
8
if (head.next.val == val) {
9
head.next = head.next.next;
10
} else {
11
head = head.next;
12
}
13
}
14
if (result.val == val) {
15
result = result.next;
16
}
17
return result;
18
}
19
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0