✅ [Python/Java/C++] Simple Solution || One-Pass || Beginner Friendly || Detailed Explanation
PLEASE UPVOTE if you like \uD83D\uDE01 If you have any question, feel free to ask. \n\n While slow moves one step forward, fast moves two steps forward.\n Final
**PLEASE UPVOTE if you like** \uD83D\uDE01 **If you have any question, feel free to ask.** \n\n* While `slow` moves one step forward, `fast` moves two steps forward.\n* Finally, when `fast` reaches the end, `slow` happens to be in the middle of the linked list.\n* For example, head = [1, 2, 3, 4, 5], I **bolded** the `slow` and `fast` in the list.\n\t* step 0: `slow`: [**1**, 2, 3, 4, 5], `fast`: [**1**, 2, 3, 4, 5]\n\t* step 1: `slow`: [1, **2**, 3, 4, 5], `fast`: [1, 2, **3**, 4, 5]\n\t* step 2: `slow`: [1, 2, **3**, 4, 5], `fast`: [1, 2, 3, 4, **5**]\n\t* end because `fast` cannot move forward anymore and `return [3, 4, 5]`\n\n\n**Python**\n```\nclass Solution(object):\n    def middleNode(self, head):\n        # While slow moves one step forward, fast moves two steps forward.\n        # Finally, when fast reaches the end, slow happens to be in the middle of the linked list.\n        slow = fast = head\n        while fast and fast.next:\n            slow = slow.next\n            fast = fast.next.next\n        return slow\n```\n**C++**\n```\nclass Solution {\npublic:\n    ListNode* middleNode(ListNode* head) {\n        ListNode *slow = head, *fast = head;\n        while (fast && fast->next) {\n            slow = slow->next;\n            fast = fast->next->next;\n        }\n        return slow;\n    }\n};\n```\n**Java**\n```\nclass Solution {\n    public ListNode middleNode(ListNode head) {\n        ListNode slow = head, fast = head;\n        while (fast != null && fast.next != null) {\n            slow = slow.next;\n            fast = fast.next.next;\n        }\n        return slow;\n    }\n}\n```\n\n**PLEASE UPVOTE if you like \uD83D\uDE01 If you have any question, feel free to ask.**\n\n\n
['C', 'Python', 'C++', 'Java']