@@ -0,0 +1,1520 @@
+package easy;%0D%0A%0D%0Aimport classes.ListNode;%0D%0Aimport utils.CommonUtils;%0D%0A%0D%0A/**203. Remove Linked List Elements  QuestionEditorial Solution  My Submissions%0D%0ATotal Accepted: 74027%0D%0ATotal Submissions: 249238%0D%0ADifficulty: Easy%0D%0ARemove all elements from a linked list of integers that have value val.%0D%0A%0D%0AExample%0D%0AGiven: 1 --%3E 2 --%3E 6 --%3E 3 --%3E 4 --%3E 5 --%3E 6, val = 6%0D%0AReturn: 1 --%3E 2 --%3E 3 --%3E 4 --%3E 5*/%0D%0Apublic class RemoveLinkedListElements %7B%0D%0A%09/**This is a very good question to test your understanding of pointers/memory/addresses, although it's marked as EASY.%0D%0A%09 * All the three nodes: dummy, curr and prev are indispensable.%0D%0A%0D%0A%09 * 1. Eventually, we should return dummy.next as the final result.%0D%0A%09 * 2. we assign head to curr, dummy to prev%0D%0A%09 * 3. and then we use prev and curr to traverse through the list and do the work%0D%0A%09 * 4. each time, we only move one node forward, so we don't need another while loop inside the while loop*/%0D%0A%09public ListNode removeElements(ListNode head, int val) %7B%0D%0A%09%09ListNode dummy = new ListNode(-1);%0D%0A%09%09dummy.next = head;%0D%0A%09%09ListNode curr = head, prev = dummy;%0D%0A%09%09while(curr != null)%7B%0D%0A%09%09%09if(curr.val == val)%7B%0D%0A%09%09%09%09prev.next = curr.next;%0D%0A%09%09%09%7D else %7B%0D%0A%09%09%09%09prev = prev.next;%0D%0A%09%09%09%7D%0D%0A%09%09%09curr = curr.next;%0D%0A%09%09%7D%0D%0A%09%09return dummy.next;%0D%0A%09%7D%0D%0A%09%0D%0A%09public static void main(String...strings)%7B%0D%0A%09%09RemoveLinkedListElements test = new RemoveLinkedListElements();%0D%0A%09%09int val = 1;%0D%0A%09%09ListNode head = new ListNode(1);%0D%0A%09%09ListNode res = test.removeElements(head, val);%0D%0A%09%09CommonUtils.printList(res);%0D%0A%09%7D%0D%0A%7D%0D%0A

remove linked list elements