My Javascript solution


  • 0
    S
    var removeNthFromEnd = function(head, n) {
        var array = [head],
            copy = head;
        if(head.next===null){return null}
        while(copy.next !== null){
            array.push(copy.next) 
            copy = copy.next;
        }
        if(array.length===n){return head.next}
        else{
        array[array.length-n-1].next=array[array.length-n+1];
        return head; 
        }
    };
    

Log in to reply
 

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