Linked List Cycle | LeetCode 141

AFFILIATE LINKS

Great resource I use to learn algorithms.
40% off Tech Interview Pro: http://techinterviewpro.com/terriblewhiteboard
20% off CoderPro: http://coderpro.com/terriblewhiteboard

Here is the full implementation.

let hasCycle = function(head) {
    let fastPointer = head;
    let slowPointer = head;

    while (fastPointer !== null && fastPointer.next !== null) {
      fastPointer = fastPointer.next.next;
      slowPointer = slowPointer.next;

      if (fastPointer === slowPointer) {
        return true;
      }
    }

    return false;
};