LC 876. Middle of the Linked List

Nilanjan Deb · April 5, 2020

This is my CPP solution.

class Solution {
public:
    ListNode* middleNode(ListNode* head) {
        ListNode* fast = head;
        ListNode* slow = head;
        while(fast!=NULL && fast->next!=NULL){
            slow = slow->next;
            fast = fast->next->next;
        }
        return slow;
    }
};


Dicussion Forum