Javascript solution with memory freeing


  • 0
    R
    var deleteDuplicates = function(head) {
        var far = head,
            actual = head,
            temp;
        
        while(far !== null){
            far = far.next;
            
            if(far === null || far.val !== actual.val){
                actual.next = far;
                actual = actual.next;
            }else if(far.val === actual.val){
                temp = far;
                far = far.next;
                temp.next = null;
                temp = null;
                actual.next = far;
                far = actual;
            }
            
        }
        
        return head;
        
    };

Log in to reply
 

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