203. Remove Linked List Elements
1 public ListNode removeElements(ListNode head, int val) { 2 if(head == null) { 3 return null; 4 } 5 ListNode dummy = new ListNode(-1); 6 dummy.next = head; 7 ListNode fakeHead = dummy; 8 while(dummy.next != null) { 9 if(dummy.next.val == val) { 10 dummy.next = dummy.next.next; 11 } else { 12 dummy = dummy.next; 13 } 14 } 15 return fakeHead.next; 16 }