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.

Example 1:

Input: [[0,30],[5,10],[15,20]]
Output: false

Example 2:

Input: [[7,10],[2,4]]
Output: true
class Solution {
public:
    static bool comp(Interval a, Interval b)
    {
        if(a.start<b.start) return true;
        else return false;
    }
    
    bool canAttendMeetings(vector<Interval>& intervals) {
        sort(intervals.begin(),intervals.end(),comp);
        int cur_end=INT_MIN;
        for(auto i:intervals)
        {
            if(i.start<cur_end) return false;
            else cur_end=i.end;
        }
        return true;
    }
};

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值