Write a function to detect a loop in a linked list.