I used a tricky solution, which is unstable, but beat 99%.

Change values to a randomized number and if the value occurs a second time, it means a loop.

The potential error is you choose a number which already exists in a list, by choosing a randomized number from a wider range, you can minimize this probability.

```
class Solution(object):
def hasCycle(self, head):
while head:
if head.val == 31415926:
return True
head.val = 31415926
head = head.next
return False
```