package leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * https://leetcode.com/problems/my-calendar-ii/
 */
public class Problem731 {
    private static class MyCalendarTwo {
        private final List<int[]> list = new ArrayList<>();

        public MyCalendarTwo() {
        }

        public boolean book(int start, int end) {
            for (int[] i : list) {
                if (i[0] < end && start < i[1]) {
                    if (i[2] >= 1) {
                        return false;
                    } else {
                        i[2]++;
                    }
                }
            }
            list.add(new int[]{start, end, 1});
            return true;
        }
    }

    public static void main(String[] args) {
        MyCalendarTwo calendar = new MyCalendarTwo();
        System.out.println(calendar.book(10, 20)); // true
        System.out.println(calendar.book(50, 60)); // true
        System.out.println(calendar.book(10, 40)); // true
        System.out.println(calendar.book(5, 15)); // false
        System.out.println(calendar.book(5, 10)); // true
        System.out.println(calendar.book(25, 55)); // true
    }
}

@@ -339,24 +339,51 @@
  int end) %7B%0A
+            int count = 0;%0A
             
@@ -483,15 +483,15 @@
 if (
-i%5B2%5D
+count
  %3E
-=
  1) 
@@ -555,15 +555,8 @@
    %7D
- else %7B
 %0A   
@@ -576,19 +576,34 @@
     
-    i%5B2%5D++;
+count++;%0A                %7D
 %0A   
@@ -607,32 +607,34 @@
             
+%7D%0A
         
 %7D%0A          
@@ -613,33 +613,52 @@
       %7D%0A        
-%7D
+    if (count %3E 1) %7B
 %0A               
@@ -650,33 +650,45 @@
                 
-%7D
+return false;
 %0A            %7D%0A 
@@ -727,19 +727,16 @@
 art, end
-, 1
 %7D);%0A    
@@ -872,16 +872,376 @@
 rTwo();%0A
+//        System.out.println(calendar.book(1, 10)); // true%0A//        System.out.println(calendar.book(8, 17)); // true%0A//        System.out.println(calendar.book(2, 7)); // true%0A%0A//        System.out.println(calendar.book(1, 10)); // true%0A//        System.out.println(calendar.book(6, 9)); // true%0A//        System.out.println(calendar.book(7, 8)); // false%0A%0A
         
@@ -1468,16 +1468,75 @@
 / false%0A
+        System.out.println(calendar.book(20, 30)); // true%0A
         
@@ -1639,21 +1639,980 @@
 5)); // true
+%0A%0A//        System.out.println(calendar.book(47, 50));%0A//        System.out.println(calendar.book(1, 10));%0A//        System.out.println(calendar.book(27, 36));%0A//        System.out.println(calendar.book(40, 47));%0A//        System.out.println(calendar.book(20, 27));%0A//        System.out.println(calendar.book(15, 23));%0A//        System.out.println(calendar.book(10, 18));%0A//        System.out.println(calendar.book(27, 36));%0A//        System.out.println(calendar.book(17, 25));%0A//        System.out.println(calendar.book(8, 17));%0A//        System.out.println(calendar.book(24, 33));%0A//        System.out.println(calendar.book(23, 28));%0A//        System.out.println(calendar.book(21, 27));%0A//        System.out.println(calendar.book(47, 50));%0A//        System.out.println(calendar.book(14, 21));%0A//        System.out.println(calendar.book(26, 32));%0A//        System.out.println(calendar.book(16, 21));%0A//        System.out.println(calendar.book(2, 7)); // true
 %0A    %7D%0A%7D%0A

Update problem 731