Day 8 of 30-Day LeetCode Challenge

Aanchal Patial
1 min readApr 15, 2020

Given a non-empty, singly linked list with head node head, return a middle node of linked list.

If there are two middle nodes, return the second middle node.

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

}
};

--

--

Aanchal Patial

We never really grow up, we only learn how to act in public