Skip to content

Latest commit

 

History

History
32 lines (29 loc) · 777 Bytes

File metadata and controls

32 lines (29 loc) · 777 Bytes

Screen Shot 2023-03-05 at 8 00 38 PM

LinkedList

/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @param {number} val
 * @return {ListNode}
 */
var removeElements = function(head, val) {
    let dummyHead = new ListNode(0);
    let curr = dummyHead;
    curr.next = head;

    while(curr.next) {
        if(curr.next.val === val) {
            curr.next = curr.next.next;
        } else {
            curr = curr.next;
        }
    }
    return dummyHead.next;
};