If you simply want to find the answer, do the tortoise-hare to determine at what point there is definitely a loop. Then start a counter, and count how many iterations you must make to reach the point that you first found. This may not be the most efficient possible, but it gives a correct answer.
Some C++ code:
#include <iostream>
struct node
{
node(node* next)
: next(next)
{ }
node* next;
};
int main(int argc, char* argv[])
{
node h(NULL), g(&h), f(&g), e(&f), d(&e), c(&d), b(&c), a(&b);
h.next = &c;
node* tortoise = &a;
node* hare = &b;
while(tortoise != hare)
{
tortoise = tortoise->next;
hare = hare->next->next;
}
int count = 1;
tortoise = tortoise->next;
while(tortoise != hare)
{
++count;
tortoise = tortoise->next;
}
std::cout << "Size of cycle: " << count << "\n";
return 0;
}
Note that you'll have to do some extra work to determine if you hit the end, rather than looping, in the case that you don't actually have a cycle. Traditional tortoise-hare should take care of that:
http://en.wikipedia.org/wiki/Cycle_detection