模拟穷举 731. 我的日程安排表 II
思路开始
如果出现了三个线段在一个时段出现了,则就是三重
暴力遍历
class MyCalendarTwo { List<int[]> booked; List<int[]> overlaps; public MyCalendarTwo() { booked = new ArrayList<int[]>(); overlaps = new ArrayList<int[]>(); } public boolean book(int start, int end) { for(int[] arr:overlaps){ int l = arr[0], r = arr[1]; if (l < end && start < r) { return false; } } for (int[] arr : booked) { int l = arr[0], r = arr[1]; if (l < end && start < r) { overlaps.add(new int[]{ Math.max(l, start), Math.min(r, end)}); } } booked.add(new int[]{ start,end}); return true; } }
如有错误欢迎指正