码迷,mamicode.com
首页 > 其他好文 > 详细

Meeting Rooms

时间:2016-07-24 07:01:11      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

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.

 

 

解法重点:

sorting array by using Comparator:

http://stackoverflow.com/questions/37150402/sorting-2d-arrays-using-java-comparator

/**
 * 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) {
        if(intervals==null)return false;
        
        
        Arrays.sort(intervals,new Comparator<Interval>(){
           @Override
            public int compare(Interval a, Interval b){return a.start-b.start;}
        });
        
        for(int i=1;i<intervals.length;i++)
        {
            if(intervals[i].start<intervals[i-1].end)
            return false;
        }
        
        return true;
    }
}

 

Meeting Rooms

标签:

原文地址:http://www.cnblogs.com/hygeia/p/5700017.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!