javascript solution


  • 0
    S
    var removeElements = function(head, val) {
        
        if(head === null) return head;
        
        while((head!==null) && (head.val==val)){
            head=head.next;
        }
        
        if(head === null) return head;
        
        var aux = head;
        
        while(aux.next!==null){
            if(aux.next.val!==val) {
                aux = aux.next;
            } else {
                aux.next = aux.next.next;
            }
        }
        
        return head;
    };
    

Log in to reply
 

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