Detect loop in linked list