876_MiddleoftheLinkedList - a920604a/leetcode GitHub Wiki
- Linked List
- Two Pointers
categories: leetcode
comments: false
title: 876. Middle of the Linked List
tags:problem
solution
class Solution {
public:
ListNode* middleNode(ListNode* head) {
ListNode *slow = head, *fast = head;
while(fast && fast->next ){
fast = fast->next->next;
slow= slow->next;
}
return slow;
}
};
analysis
- time complexity
O(n)
- speed complexity
O(1)