//快慢指针
public class Solution { public boolean hasCycle(ListNode head) { if (head == null || head.next == null) { return false; } ListNode fastNode = head.next; ListNode slowNode = head; while (fastNode != slowNode) { if (fastNode == null || fastNode.next == null) { return false; } fastNode = fastNode.next.next; slowNode = slowNode.next; } return true; } }