Skip to content

Commit 15d2825

Browse files
committed
Add Solution.java to problems 0203
1 parent f936783 commit 15d2825

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* public class ListNode {
4+
* int val;
5+
* ListNode next;
6+
* ListNode(int x) { val = x; }
7+
* }
8+
*/
9+
class Solution {
10+
public ListNode removeElements(ListNode head, int val) {
11+
ListNode root = new ListNode(0);
12+
root.next = head;
13+
ListNode res = root;
14+
while (root.next != null) {
15+
if (root.next.val == val) {
16+
root.next = root.next.next;
17+
} else {
18+
root = root.next;
19+
}
20+
}
21+
return res.next;
22+
}
23+
}

0 commit comments

Comments
 (0)