public int hasLoop(MySinglyLinkedList first) {

        if(first == null) // list does not exist..so no loop either.
            return 0;

        MySinglyLinkedList slow, fast; // create two references.

        slow = fast = first; // make both refer to the start of the list.



        while(true) {

            slow = slow.nextNode;          // 1 hop.

            if(fast.nextNode != null)
                fast = fast.nextNode.nextNode; // 2 hops.
            else
                return 0;          // next node null => no loop.

            if(slow == null || fast == null) // if either hits null..no loop.
                return 0;

            if(slow == fast) { // if the two ever meet...we must have a loop.

                int cnt = 1;
                slow = slow.nextNode;
                StringBuffer buffer = new StringBuffer();
                while (slow != fast) {
                    buffer.append(slow.value);
                    cnt++;
                    slow = slow.nextNode;
                }
                buffer.append(fast.value);

                String t = cnt + buffer.toString();



                return Integer.parseInt(t);
            }


        }
    }