Double star programming. Not quite readable

  • 0

    double star is quite useful when doing linked list insertion/deletion.

    ListNode* removeNthFromEnd(ListNode* head, int n) {
        if(!head || !n) return NULL;
        ListNode** dlt = NULL;
        ListNode* tail = head;
        int interval = 0;
        while(tail) {
            if(interval < n-1) ++interval;
            else {
                if(!dlt) dlt = &head;
                else dlt = &((*dlt)->next);
            tail = tail->next;
        if(dlt) (*dlt) = (*dlt)->next;
        return head;

    Besides, is recursive solution considered one pass? I thought that means two passes. Hmmm.

Log in to reply

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