Skip to content

Instantly share code, notes, and snippets.

@linnykoleh
Created April 9, 2017 11:44

Revisions

  1. linnykoleh created this gist Apr 9, 2017.
    14 changes: 14 additions & 0 deletions RemoveElements.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    public ListNode removeElements(ListNode head, int val) {
    final ListNode fake = new ListNode(-1);
    fake.next = head;

    ListNode cur = fake;
    while(cur.next != null){
    if(cur.next.val == val){
    cur.next = cur.next.next;
    }else{
    cur = cur.next;
    }
    }
    return fake.next;
    }