package leetcode;

/**
 * https://leetcode.com/problems/my-calendar-iii/
 */
public class Problem732 {
    private static class MyCalendarThree {
        public MyCalendarThree() {
        }

        public int book(int start, int end) {
            // TODO
            return 0;
        }
    }

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

@@ -12,16 +12,65 @@
 tcode;%0A%0A
+import java.util.Map;%0Aimport java.util.TreeMap;%0A%0A
 /**%0A * h
@@ -188,16 +188,102 @@
 Three %7B%0A
+        private final Map%3CInteger/*num*/, Integer/*count*/%3E delta = new TreeMap%3C%3E();%0A%0A
         
@@ -382,37 +382,84 @@
     
-// TODO%0A            return 0;
+delta.put(start, delta.getOrDefault(start, 0) + 1); // increment start count
 %0A   
@@ -467,453 +467,298 @@
     
-%7D%0A
     
-%7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        MyCalendarThree calendar = new MyCalendarThree();%0A        System.out.println(calendar.book(10, 20)); // 1%0A        System.out.println(calendar.book(50, 60)); // 1%0A        System.out.println(calendar.book(10, 40)); // 2%0A        System.out.println(calendar.book(5, 15)); // 3%0A        System.out.println(calendar.book(5, 10)); // 3%0A        System.out.println(calendar.book(25, 55)); // 3
+delta.put(end, delta.getOrDefault(end, 0) - 1); // decrement end count%0A%0A            int count = 0;%0A            int max = 0;%0A            for (int d : delta.values()) %7B%0A                count += d;%0A                max = Math.max(max, count);%0A            %7D%0A            return max;%0A        %7D
 %0A   

Solve problem 732