Using 2 Methods || Beats 100% || Easiest Solution
\n# Approach 1\nTraverse the whole linked list and get lenght of list. Now traverse the list again till count/2 and return the node at count/2. \nBelow is the i
\n# Approach 1\nTraverse the whole linked list and get lenght of list. Now traverse the list again till count/2 and return the node at count/2. \nBelow is the implementation of the above approach:\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n) where n is no of nodes in linked list\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n\nclass Solution {\npublic:\n\n    int getlen(ListNode* head){\n        int len =0;\n        while(head != NULL){\n            head=head->next;\n            len++;\n        }\n        return len;\n    }\n    ListNode* middleNode(ListNode* head) \n    {\n\n        int ans = getlen(head);\n        int mid = ans/2;\n\n        int cnt=0;\n        ListNode* temp = head;\n        while(cnt<mid){\n            temp=temp->next;\n            cnt++;\n        }\n        return temp;\n\n        \n    }\n};\n```\n\n# Approach 2\nTraverse linked list using two-pointers. Move one pointer by one and the other pointers by two. When the fast pointer reaches the end, the slow pointer will reach the middle of the linked list.\nBelow is the implementation of the above approach:\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n) where n is no of nodes in linked list\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n```\nclass Solution {\npublic:\n    ListNode* middleNode(ListNode* head) \n    {\n        ListNode* slow = head;\n        ListNode* fast = head;\n        \n        while(fast && fast->next)\n        {\n            slow=slow->next;\n            fast=fast->next->next;\n        }\n        return slow;\n    }\n};\n```\n![7abc56.jpg](https://assets.leetcode.com/users/images/f433047b-bb67-4648-bcb8-37c160139644_1676929303.399673.jpeg)\n
['Linked List', 'C++']