My Javascript Solution


  • 1
    R
    var removeElements = function(head, val) {
        var current = head;
        var previous = null;
        
        while(current){
            if(current.val === val){
                if(previous){
                    previous.next = current.next;
                }else{
                    head = current.next;
                }
            }else{
                previous = current;
            }
            
            current = current.next;
        }
        
        return head;
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.