zoukankan      html  css  js  c++  java
  • [LeetCode] Meeting Rooms

    Problem Description:

    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


    The idea is pretty simple: first we sort the intervals in the ascending order of start; then we check for the overlapping of each pair of neighboring intervals. If they do, then return false; after we finish all the checks and have not returned false, just return true.

    Sorting takes O(nlogn) time and the overlapping checks take O(n) time, so this idea is O(nlogn) time in total.

    The code is as follows.

     1 class Solution {
     2 public:
     3     bool canAttendMeetings(vector<Interval>& intervals) {
     4         sort(intervals.begin(), intervals.end(), [](Interval& l, Interval& r){return l.start < r.start;});
     5         int n = intervals.size();
     6         for (int i = 0; i < n - 1; i++) {
     7             if (intervals[i].end > intervals[i + 1].start) {
     8                 return false;
     9             }
    10         }
    11         return true;
    12     }
    13 };
  • 相关阅读:
    d3的一些总结
    NPashaP的二分图源码部分
    python的web服务器
    d3碰撞源码分析
    测试cnblog文章内部JS
    仿淘宝 vue
    webpack散记---代码分割 和 懒加载
    webpack散记---提取公共代码
    webpack散记--Typescript
    webpack随笔2--编译ES6/ES7
  • 原文地址:https://www.cnblogs.com/jcliBlogger/p/4713035.html
Copyright © 2011-2022 走看看