I want to let the every node's next node reference to head node. It's just set a flag on every node.

if there doesn't has cycle, there the last node is null. return false;

but if there has cycle, I will find it via the flag which next node is head node.

this is another version. I use empty node to flag, it's more easier to understand.

public boolean hasCycle(ListNode head) {

```
if(head == null || head.next == null) {
return false;
}
ListNode empty = new ListNode(1);
ListNode node = head;
while(node != null) {
if(node.next == empty) {
return true;
}
ListNode temp = node.next;
node.next = empty;
node = temp;
}
return false;
}
```