Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...]
(si < ei), determine if a person could attend all meetings.
For example,
Given[[0, 30],[5, 10],[15, 20]]
,return false
. 思路:把所有都interval按照start time从小到大sort一遍,然后挨个比较i和i+1的start和endtime使它们不相交,不重叠。如果重叠,就是false熟悉lamdba的用法
(a,b)->(a.val-b.val) increasing order
(a,b) -> (b.val-a.val) decreasing order
/** * Definition for an interval. * public class Interval { * int start; * int end; * Interval() { start = 0; end = 0; } * Interval(int s, int e) { start = s; end = e; } * } */public class Solution { public boolean canAttendMeetings(Interval[] intervals) { Arrays.sort(intervals,(a,b)->(a.start-b.start)); for(int i=0;i