Is my 8 lines JS recursive solution one pass?


  • 0
    E
    var removeNthFromEnd = function(head, n) {
        function count(node) {
            reverseCount = !node.next ? 1 : count(node.next) + 1;
            if (reverseCount == n + 1) node.next = node.next.next;
            return reverseCount;
        }
        return count(head) == n ? head.next : head;
    };
    

    I'm not sure if my solution is one pass.


Log in to reply
 

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