Skip to content

Latest commit

 

History

History
21 lines (16 loc) · 328 Bytes

linked-list.md

File metadata and controls

21 lines (16 loc) · 328 Bytes

Linked Lists

Detecting loops

const hasCycle = (head) => {
    let hare = head;
    let tort = head;
        
    while (hare && hare.next) {
        hare = hare.next.next;
        tort = tort.next;
        
        if (hare === tort) return true;
    }
    
    return false;
};