mirror of
https://github.com/TheAlgorithms/C
synced 2025-04-22 13:16:14 +03:00
20 lines
355 B
C
20 lines
355 B
C
/**
|
|
* Definition for singly-linked list.
|
|
* struct ListNode {
|
|
* int val;
|
|
* struct ListNode *next;
|
|
* };
|
|
*/
|
|
|
|
|
|
struct ListNode* middleNode(struct ListNode* head){
|
|
struct ListNode *fast, *slow;
|
|
fast = slow = head;
|
|
while(fast && fast->next) {
|
|
slow = slow -> next;
|
|
fast = fast -> next -> next;
|
|
}
|
|
return slow;
|
|
}
|
|
|