Skip to content

Latest commit

 

History

History
20 lines (17 loc) · 391 Bytes

203RemoveLinkedListElements.md

File metadata and controls

20 lines (17 loc) · 391 Bytes

203. Remove Linked List Elements

集邮。

public ListNode removeElements(ListNode head, int val) {
    ListNode dummy = new ListNode(-1);
    dummy.next = head;
    head = dummy;
    while(head.next != null) {
        if(head.next.val == val) {
            head.next = head.next.next;
        } else {
            head = head.next;
        }
    }
    return dummy.next;
}