Python3 easiest 2 methods
Approach 1\n Describe your approach to solving the problem. \n- create array mapped in which we will store all nodes of list.\n- while traversing nodes count nu
# Approach 1\n<!-- Describe your approach to solving the problem. -->\n- create array mapped in which we will store all nodes of list.\n- while traversing nodes count number of nodes in list.\n- now if n is even put k = ceiling(n/2) else n // 2.\n- now return mapped[k]\n\n![Capture.PNG](https://assets.leetcode.com/users/images/0962e6d2-ffd3-4591-96f4-dfc20abf2b90_1678295083.9449859.png)\n\n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nfrom math import ceil\nclass Solution:\n    def middleNode(self, head: Optional[ListNode]) -> Optional[ListNode]:\n        mapped = []\n        n = 0\n        while head:\n            mapped.append(head)\n            n += 1\n            head = head.next\n        k = n // 2 if n % 2 else ceil(n/2)\n        return mapped[k]\n```\n---\n# Approach 2\n- use yield to get forward and backward series of list.\n- while getting values pass one value as val, indicating it\'s position in list.\n- now we have our forward and reversed series.\n- traver both together and when encountered position of left element >= right element we know it is the middle value.\n- return left\n# Complexity\n- Time complexity: O(3N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(2N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n# Code\n```\nclass Solution:\n    def middleNode(self, head: Optional[ListNode]) -> Optional[ListNode]:\n        def reverse(curr=head, val=0):\n            if curr:\n                for i in reverse(curr.next, val+1):\n                    yield i\n                yield [curr, val]\n        def forward(curr=head, val=0):\n            if curr:\n                yield [curr, val]\n                for i in forward(curr.next, val+1):\n                    yield i      \n        def middle():\n            front = forward()\n            end = reverse()\n            for left, right in zip(front, end):\n                if left[1] >= right[1]:return left[0]\n        return middle()\n```\n# Please like anc comment below :-)
['Linked List', 'Math', 'Python3']