Very Easy || 0 ms || 100% || Fully Explained || Java, C++, Python, JS, C, Python3 || Two-Pointers
Java Solution:\n\n// Runtime: 0 ms, faster than 100.00% of Java online submissions for Middle of the Linked List.\n// Time Complexity :  O(n)\n// Space Complexi
# **Java Solution:**\n```\n// Runtime: 0 ms, faster than 100.00% of Java online submissions for Middle of the Linked List.\n// Time Complexity :  O(n)\n// Space Complexity : O(1)\nclass Solution {\n    public ListNode middleNode(ListNode head) {\n        // Initialize two pointers p1 and p2 pointing to the head...\n        ListNode p1 = head;\n        ListNode p2 = head;\n        while(p2 != null && p2.next != null){\n            // In each iteration, we move p1 one node forward and we move p2 two nodes forward...\n            p1 = p1.next;\n            p2 = p2.next.next;\n        }\n        // When p2 reaches the last node, p1 will be exactly at the middle point...\n        return p1;\n    }\n}\n```\n\n# **C++ Solution:**\n```\n// Time Complexity : O(n)\n// Space Complexity : O(1)\nclass Solution {\npublic:\n    ListNode* middleNode(ListNode* head) {\n        // Initialize two pointers p1 and p2 pointing to the head...\n        ListNode* p1 = head;\n        ListNode* p2 = head;\n        // Base case...\n        if(head == NULL) return NULL;\n        else {\n            while(p2 != NULL and p2->next != NULL) {\n                // In each iteration, we move p1 one node forward and we move p2 two nodes forward...\n                p2 = p2->next->next;\n                p1 = p1->next;\n            }\n            // When p2 reaches the last node, p1 will be exactly at the middle point...\n            return p1;\n        }\n    }\n};\n```\n\n# **Python/Python3 Solution:**\n```\n# Time Complexity :  O(n)\n# Space Complexity : O(1)\nclass Solution(object):\n    def middleNode(self, head):\n        # We need two pointers, one is head with one step each iteration, and the other is tmp with two steps each iteration.\n        temp = head\n        while temp and temp.next:\n            # In each iteration, we move head one node forward and we move temp two nodes forward...\n            head = head.next\n            temp = temp.next.next\n        # When temp reaches the last node, head will be exactly at the middle point...\n        return head\n```\n        \n# **JavaScript Solution:**\n```\n// Time Complexity :  O(n)\n// Space Complexity : O(1)\nvar middleNode = function(head) {\n    // Initialize two pointers p1 and p2 pointing to the head...\n    var p1 = head;\n    var p2 = head;\n    while(p2 != null && p2.next != null){\n        // In each iteration, we move p1 one node forward and we move p2 two nodes forward...\n        p1 = p1.next;\n        p2 = p2.next.next;\n    }\n    // When p2 reaches the last node, p1 will be exactly at the middle point...\n    return p1;\n};\n```\n\n# **C Language:**\n```\n// Time Complexity :  O(n)\n// Space Complexity : O(1)\nstruct ListNode* middleNode(struct ListNode* head){\n    // Initialize two pointers p1 and p2 pointing to the head...\n    struct ListNode* p1 = head;\n    struct ListNode* p2 = head;\n    // Base case...\n    if(head == NULL) return NULL;\n    else {\n        while(p2 != NULL && p2->next != NULL) {\n            // In each iteration, we move p1 one node forward and we move p2 two nodes forward...\n            p2 = p2->next->next;\n            p1 = p1->next;\n        }\n        // When p2 reaches the last node, p1 will be exactly at the middle point...\n        return p1;\n    }\n}\n```\n**I am working hard for you guys...\nPlease upvote if you found any help with this code...**
['Linked List', 'Two Pointers', 'C', 'Python', 'Java', 'Python3', 'JavaScript']