[LeetCode 252] Meeting Rooms
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
.
Solution:
sort the interval based on the start time, if have same start time use end time.
go through interval to see if there any overlaps.
class Interval {
int start;
int end;
public Interval(int start, int end) {
this.start = start;
this.end = end;
}
}
public boolean canAttendMeetings(Interval[] intervals) {
Arrays.sort(intervals, new Comparator<Interval>() {
@Override
public int compare(Interval o1, Interval o2) {
int r = o1.start - o2.start;
return r==0? o1.end - o2.end : r;
}
});
for(int i=1;i<intervals.length;i++) {
Interval t1 = intervals[i-1];
Interval t2 = intervals[i];
if(t1.end>t2.start) return false;
}
return true;
}
相關文章
- LeetCode #252 - Meeting RoomsLeetCodeOOM
- Leetcode 252 Meeting RoomsLeetCodeOOM
- LeetCode252 Meeting RoomsLeetCodeOOM
- leetcode-252-Meeting RoomsLeetCodeOOM
- 252. Meeting RoomsOOM
- Leetcode 252. Meeting Rooms (Easy) (cpp)LeetCodeOOM
- LeetCode 252. Meeting Rooms (Java版; Easy)LeetCodeOOMJava
- LeetCode 252. Meeting Rooms(會議室)LeetCodeOOM
- [leetcode] 252. Meeting Rooms 解題報告LeetCodeOOM
- Leetcode: Meeting RoomsLeetCodeOOM
- LeetCode-Meeting Rooms IILeetCodeOOM
- [LeetCode 253] Meeting Rooms IILeetCodeOOM
- *LeetCode-Meeting Rooms IILeetCodeOOM
- [LintCode/LeetCode] Meeting RoomsLeetCodeOOM
- [Leetcode]253. Meeting Rooms IILeetCodeOOM
- [LeetCode] Meeting Rooms 會議室LeetCodeOOM
- LeetCode 題解(254) : Meeting RoomsLeetCodeOOM
- [LeetCode253]Meeting Rooms IILeetCodeOOM
- Leetcode 252. Meeting Room 253. Meeting Room IILeetCodeOOM
- Meeting Rooms IIOOM
- LeetCode 253. Meeting Rooms II(會議室)LeetCodeOOM
- Leetcode 253:Meeting Rooms II(超詳細的解法!!!)LeetCodeOOM
- [Leetcode] 253. Meeting Rooms II 解題報告LeetCodeOOM
- 253. Meeting Rooms IIOOM
- 【LeetCode】253. Meeting Rooms II 解題報告(C++)LeetCodeOOMC++
- Facebook面試題 meeting rooms 求同時最多meeting room的時間面試題OOM
- LeetCode—253.會議室 II(Meeting Rooms II)——分析及程式碼(C++)LeetCodeOOMC++
- [LeetCode] 252、會議室LeetCode
- Leetcode 253: meeting roomLeetCodeOOM
- LeetCode-Best Meeting PointLeetCode
- LeetCode 252. 會議室(排序)LeetCode排序
- 【leetcode】252 會議室(陣列)LeetCode陣列
- LeetCode 題解(252) : Find the Duplicate NumberLeetCode
- LeetCode-Python-252. 會議室LeetCodePython
- Leetcode Meeting room問題系列 - 2LeetCodeOOM
- Leetcode Meeting room問題系列 - 1LeetCodeOOM
- Management of Remote Dependencies (252)REM
- leetcode-區間問題總結(56,252,253,1094,435,452,646LeetCode