Given a linked list, determine if it has a cycle in it.
Whether the fast node can meet the slow node?
public boolean hasCycle(ListNode head) {
if (head==null) {
return false;
}
ListNode current = head;
ListNode fast = head;
while (fast.next!=null && fast.next.next!=null) {
current = current.next;
fast = fast.next.next;
if (current==fast) {
return true;
}
}
return false;
}