Easy Code with 100% beats with c++ || Beginner Friendly
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nThe approach is to traverse the linked list to find its length (count), t
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nThe approach is to traverse the linked list to find its length (count), then traverse again to the middle of the list. In the second traversal, move count/2 nodes to reach the middle. This works because we already know the length of the linked list.\n\n# Complexity\n- Time complexity:\nThe time complexity is O(N), where N is the number of nodes in the linked list. This is because we traverse the entire linked list twice.\n\n- Space complexity:\nThe space complexity is O(1), as we are using only a constant amount of extra space for pointers and variables, regardless of the input size\n\n# Code\n```c++ []\nclass Solution {\npublic:\n    ListNode* middleNode(ListNode* head) {\n        ListNode* ptr=head;\n        int count=0;\n        while(ptr!=NULL)\n        {\n            count++;\n            ptr=ptr->next;\n        }\n        ptr=head;\n        for(int i=0;i<count/2;i++)\n        ptr=ptr->next;\n        return ptr;\n    }\n};\n```\n```python []\nclass Solution(object):\n    def middleNode(self, head):\n        count = 0\n        ptr = head\n        while ptr is not None:\n            count += 1\n            ptr = ptr.next\n        \n        ptr = head\n        for i in range(count // 2):\n            ptr = ptr.next\n        \n        return ptr\n    \n```\n```java []\nclass Solution {\n    public ListNode middleNode(ListNode head) {\n        ListNode ptr = head;\n        int count = 0;\n        while (ptr != null) {\n            count++;\n            ptr = ptr.next;\n        }\n\n        ptr = head;\n        for (int i = 0; i < count / 2; i++) {\n            ptr = ptr.next;\n        }\n\n        return ptr;\n    }\n}\n\n```\n```javascript []\nvar middleNode = function(head) {\n    let count = 0;\n        let ptr = head;\n        while (ptr !== null) {\n            count++;\n            ptr = ptr.next;\n        }\n\n        ptr = head;\n        for (let i = 0; i < Math.floor(count / 2); i++) {\n            ptr = ptr.next;\n        }\n\n        return ptr;\n};\n```\n![upvote.jpeg](https://assets.leetcode.com/users/images/998b3890-e15a-4305-b1cc-53bf121e3857_1709781698.34867.jpeg)\n
['Linked List', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']