🚀 C++ Easy approach | Tortoise and Hare algo | Fastest  🚀
Approach 1: \nThe Brute force for the approach can be to find the number of nodes in the linkedlist and then traversing over the linkedlist to the half of the n
**Approach 1**: \nThe Brute force for the approach can be to find the number of nodes in the linkedlist and then traversing over the linkedlist to the half of the nodes of the linkedlist and to print the data of the node. The code for the same is as follows.\n```\nclass Solution {\npublic:\n    int getlength(ListNode*head){\n        int count=0;\n        while(head!=NULL){\n            count++;\n            head=head->next;\n        }\n        \n        return count;\n    }\n    ListNode* middleNode(ListNode* head) {\n        int n=getlength(head);\n        for(int i=1;i<=n/2;i++){\n            head=head->next;\n        }\n        return head;\n        \n    }\n};\n```\n**Approach 2 i.e; Floyd\'s Tortoise and Hare algorithm** :\nAccording to the algo suppose there is a tortoise and a hare in a linkedlist , everytime the tortoise takes a step ahead the hare do steps ahead. that means when the hare will reach the end of the linked list then the tortoise will be at the middle of the linkedlist . This method will save us from firstly counting the number of nodes in the linkedlist and then traversing over them. Go through the code to have a clear understanding.\n```\nclass Solution {\npublic:\n   \n    ListNode* middleNode(ListNode* head) {\n       ListNode*Hare=head;\n       ListNode*Tortoise=head;\n        \n        while(Hare != NULL && Hare->next!=NULL){\n            Hare=Hare->next->next;\n            Tortoise=Tortoise->next;\n        }\n        return Tortoise;\n        \n    }\n};\n```\nHope this helped , do give a upvote if you find this useful.\n\n
['Linked List']