Javascript two pointers (fast & slow)
Fast pointer will move two steps at a time while slow pointer move one step at a time. So when fast pointer reach at the end of the linked list, slow pointer wi
Fast pointer will move two steps at a time while slow pointer move one step at a time. So when fast pointer reach at the end of the linked list, slow pointer will be at the middle of the linked list.\n\n```\n/*\ninitial state\nf\n1 -> 2 -> 3 -> 4 -> 5\ns\n\n1st loop\n\t\t  f\n1 -> 2 -> 3 -> 4 -> 5\n     s\n\t \n2nd loop\n\t\t            f\n1 -> 2 -> 3 -> 4 -> 5\n          s\n\nwhen f reach end of the linked list, s will be at the middle.\n\nf = fast pointer\ns = slow pointer\n*/\n\nvar middleNode = function(head) {\n    let fast = slow = head;\n    while (fast && fast.next) {\n        fast = fast.next.next;\n        slow = slow.next;\n    }\n    return slow;\n};\n```
['Two Pointers', 'JavaScript']