Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 15d2825

Browse files
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
Lines changed: 23 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /