Detect loop in a linked list