public boolean hasCycle(ListNode head) {//pass
        if (head == null) {
            return false;
        }
        ListNode p1 = head;
        ListNode p2 = head.next;
        while (p1 != null && p2 != null) {
            if (p1 == p2) {
                return true;
            }
            else {
                if (p1.next == null) return false;
                else p1 = p1.next;
                if ((p2.next == null) || (p2.next != null && p2.next.next == null)) return false;
                else p2 = p2.next.next;
            }
        }
        return false;
    }