Skip to content

Latest commit

 

History

History
30 lines (28 loc) · 956 Bytes

File metadata and controls

30 lines (28 loc) · 956 Bytes

Linked List

Screen Shot 2023-03-06 at 12 30 37 PM

Screen Shot 2023-03-06 at 12 30 46 PM

We don't need dummyHead = new ListNode(0) because there's no need to remove the first element.

/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var deleteDuplicates = function(head) {
    let curr = head;
    while(curr && curr.next) {
        if(curr.val === curr.next.val) {
            curr.next = curr.next.next;
        } else {
            curr = curr.next;
        }
    }
    return head;
};