One pass 3ms C++ solution

  • 0
    class Solution {
        ListNode* removeNthFromEnd(ListNode* head, int n) {
            if(n == 0) return head;
            ListNode temp = ListNode(100);
            ListNode* p = &temp;
            p->next = head;
            onePassFindN(p, n);
            return p->next;
        int onePassFindN(ListNode* l, int n){
                return 0;
            int i;
            if((i = onePassFindN(l->next, n)) == n)
                l->next = l->next->next;
            return 1+i;

Log in to reply

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