JAVASCRIPT 100% EASY  ||  WITH SIMPLE EXPLANATION  ||  TWO POINTERS
Approach\n1. Two pointers are initialized to point to the head node: twice and once.\n\n2. A while loop is started, which runs as long as both twice and twice.n
# Approach\n1. Two pointers are initialized to point to the head node: twice and once.\n\n2. A while loop is started, which runs as long as both twice and twice.next are not null. This loop traverses the linked list using the two pointers, with twice moving forward two nodes at a time and once moving forward one node at a time.\n\n3. Once the loop terminates, the once pointer will be pointing to the middle node of the linked list. This is because twice has moved twice as fast as once, so when twice reaches the end of the linked list, once will have traversed exactly half of the list.\n\n4. Finally, the function returns the once pointer, which points to the middle node of the linked list.\n\n# Here how it works:\n\n\n```\nLet\'s simply call thes pointer like these:\n\nTwice => t\nOnce  => o\n\n\n         o\nFirst: [ 1-> 2 -> 3 -> 4 -> 5 -> 6]\n         t\n\n             o\nFirst: [ 1-> 2 -> 3 -> 4 -> 5 -> 6]\n                  t\n\n                  o                \nFirst: [ 1-> 2 -> 3 -> 4 -> 5 -> 6]\n                                 t\n\nThen, it will return Once linked list which is middle of original linked list\n```\n\n# Complexity\n- Time complexity:\nIt is actually is O(n), where n is the length of the linked list. This is because the code iterates through the linked list only once, using two pointers that move at different speeds. Since the code does a constant amount of work for each node in the list, the time complexity is linear with respect to the length of the list.\n\n- Space complexity:\nIt is O(1), which is constant space. This is because the code uses only two pointers (twice and once) to keep track of the middle node, regardless of the size of the linked list. Therefore, the space used by the algorithm does not depend on the size of the input, but rather on a fixed number of variables used by the algorithm.\n\nPLEASE, DON\'T FORGET TO LIKE IF IT WAS HELPFUL, THANKS\n\n# Code\n```\n/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n *     this.val = (val===undefined ? 0 : val)\n *     this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar middleNode = function(head) {\n    let twice = head;\n    let once = head;\n    while(twice && twice.next){\n        twice = twice.next.next;\n        once = once.next\n    }\n    return once\n};\n```
['JavaScript']