Skip to content

Instantly share code, notes, and snippets.

@linnykoleh
Created April 9, 2017 11:44
Show Gist options
  • Save linnykoleh/604b0851eb7d675b2eb4acdca7bfab12 to your computer and use it in GitHub Desktop.
Save linnykoleh/604b0851eb7d675b2eb4acdca7bfab12 to your computer and use it in GitHub Desktop.
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment