Clean 10 lines C++


  • 0
        ListNode* removeNthFromEnd(ListNode* head, int n) {
            ListNode* slow=head;
            ListNode* fast=head;
            while(n>0) fast=fast->next,n--;
            if(!fast) return slow->next;
            while(fast->next){
                slow=slow->next;
                fast=fast->next;
            }
            slow->next=slow->next->next;
            return head;
        }
    

Log in to reply
 

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