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 c520c4f commit 0992ba4Copy full SHA for 0992ba4
Remove Linked List Elements
@@ -0,0 +1,24 @@
1
+/**
2
+ * Definition for singly-linked list.
3
+ * public class ListNode {
4
+ * int val;
5
+ * ListNode next;
6
+ * ListNode() {}
7
+ * ListNode(int val) { this.val = val; }
8
+ * ListNode(int val, ListNode next) { this.val = val; this.next = next; }
9
+ * }
10
+ */
11
+class Solution {
12
+ public ListNode removeElements(ListNode head, int val) {
13
+ ListNode res = new ListNode(0);
14
+ res.next = head;
15
+ ListNode cur = res;
16
+ while (cur != null && cur.next != null) {
17
+ if (cur.next.val == val)
18
+ cur.next = cur.next.next;
19
+ else
20
+ cur = cur.next;
21
+ }
22
+ return res.next;
23
24
+}
0 commit comments