One pass JavaScript solution


  • 1
    L
    var removeNthFromEnd = function(head, n) {
      var left, before, right = head;
      left = before = {next: head}; 
      while (n--) right = right.next;
      while (right) {
        right = right.next;
        left = left.next;
      }
      left.next = left.next.next;
      return before.next;
    };

  • 0
    X

    good.How can you do it.


Log in to reply
 

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