Linked List Part-3
Lancelot03
Posted on August 10, 2022
find the middle element of a singly linked list without iterating the list more than once?
Solution- ### Python
Node* getMiddle(Node *head)
{
struct Node *slow = head;
struct Node *fast = head;
if (head)
{
while (fast != NULL && fast->next != NULL)
{
fast = fast->next->next;
slow = slow->next;
}
}
return slow;
}
💖 💪 🙅 🚩
Lancelot03
Posted on August 10, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
beginners "🚀 From Algorithms to Applications: My Journey as a Machine Learning Developer 🤖"
June 19, 2024