public boolean hasCycle(ListNode head) {
        if (head == null || head.next == null) {
            return false;
        }

        ListNode second = head;
        while (head != null && second != null) {
            head = head.next;
            second = second.next;
            if (second != null) {
                second = second.next;
            }
            if (head == second) {
                return true;
            }
        }
        return false;

    }