PYTHON || 100% EFFICIENT🔥|| OPTIMAL SOLUTION || EASY TO UNDERSTAND ||
if it\'s help, please up \u2B06vote!\u2764\uFE0F and comment\uD83D\uDD25\n# Intuition\n Describe your first thoughts on how to solve this problem. \n- The intui
# if it\'s help, please up \u2B06vote!\u2764\uFE0F and comment\uD83D\uDD25\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- The intuitive approach to this problem is to find a way to traverse the linked list and identify the middle node. One way to do this is to use two pointers, one moving twice as fast as the other, so that when the faster pointer reaches the end, the slower pointer will be at the middle.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Initialize two pointers, slow and fast, both pointing to the head of the linked list.\n- Move the fast pointer twice as fast as the slow pointer.\n- In a loop, move the slow pointer one step and the fast pointer two steps until the fast pointer reaches the end of the linked list.\n- When the fast pointer reaches the end (or the last node for odd-length lists), the slow pointer will be at the middle of the linked list.\n- Return the slow pointer, which points to the middle node.\n# Complexity\n- Time complexity: $O(n)$\nWhere n is the number of nodes in the linked list.\nWe need to traverse the entire linked list once, so the time complexity is linear with respect to the length of the list.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $O(1)$\nWe only use two additional pointers, slow and fast, regardless of the size of the input.\nTherefore, the space complexity is constant and does not depend on the input size.\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution(object):\n    def middleNode(self, head):\n        # Initialize two pointers, slow and fast, both pointing to the head\n        slow = fast = head\n        # Move the fast pointer twice as fast as the slow pointer\n        while fast and fast.next:\n            # Move the slow pointer one step\n            slow = slow.next\n            # Move the fast pointer two steps\n            fast = fast.next.next\n        # When the fast pointer reaches the end (or the last node for odd length),\n        # the slow pointer will be at the middle\n        return slow\n```\n![7c17f983-3b8b-4738-b722-c1c1466f9510_1682940288.2823734.jpeg](https://assets.leetcode.com/users/images/0c733bc6-dda6-4c6b-bfaf-ab141a0bc11e_1717596447.060558.jpeg)\n
['Linked List', 'Two Pointers', 'Python', 'Python3']