Skip to content

Latest commit

 

History

History
27 lines (19 loc) · 709 Bytes

Delete the Middle Node of a Linked List.md

File metadata and controls

27 lines (19 loc) · 709 Bytes
ListNode* deleteMiddle(ListNode* head) {
        
        if(head==NULL || head->next==NULL)
            return NULL;

        ListNode* slow=head;
        ListNode* fast=head->next;          //if initializaing fast=head,this step before while  fast=fast->next->next;

        while(fast->next!=NULL){

            fast=fast->next;
            if(fast->next==NULL)
                break;
            else
                fast=fast->next;
            slow=slow->next;
        }

        slow->next=slow->next->next;
        return head;
    }

    ```