src/Common/Abstracts/AbstractLinkedList.php
public function hasLoop(): bool {
        $tortoise = $this->getHead();
        $hare = $this->getHead();

        while ($tortoise !== null && $hare->getNext() !== null) {
            $hare = $hare->getNext()->getNext();

            if (Comparator::equals($tortoise->getValue(), $hare->getValue())) {
                return true;
            }

            $tortoise = $tortoise->getNext();
        }
        return false;
    }
public function hasLoop(): bool {
        $tortoise = $this->getHead();
        $hare = $this->getHead();

        while ($tortoise !== null && $hare->getNext() !== null) {
            $hare = $hare->getNext()->getNext();

            if (Comparator::equals($tortoise->getValue(), $hare->getValue())) {
                return true;
            }

            $tortoise = $tortoise->getNext();
        }
        return false;
    }
public function hasLoop ( ) : bool { $ tortoise = $ this -> getHead ( ) ; $ hare = $ this -> getHead ( ) ; while ( $ tortoise !== null && $ hare -> getNext ( ) !== null ) { $ hare = $ hare -> getNext ( ) -> getNext ( ) ; if ( Comparator :: equals ( $ tortoise -> getValue ( ) , $ hare -> getValue ( ) ) ) { return true ; } $ tortoise = $ tortoise -> getNext ( ) ; } return false ; }
also known as the Runner Technique

@return bool
also known as the Runner Technique