clueless coding // TODO: be smarter

LeetCode Linked List Cycle: Java Solution



TL;DR Code Solution


public boolean hasCycle(ListNode head) {

    ListNode runner = head;
    ListNode follower = head;

    while (runner != null && runner.next != null) {
        runner = runner.next.next;
        follower = follower.next;

        if (runner == follower) {
            return true;
        }

    }

    return false;




}