731. My Calendar II

https://leetcode.com/problems/my-calendar-ii/description/
https://leetcode.com/problems/my-calendar-ii/solution/#approach-1-brute-force-accepted
Evidently, two events [s1, e1) and [s2, e2) do not conflict if and only if one of them starts after the other one ends: either e1 <= s2 OR e2 <= s1. By De Morgan's laws, this means the events conflict when s1 < e2 AND s2 < e1.

https://leetcode.com/problems/my-calendar-ii/solution/#approach-2-boundary-count-accepted
很像统计CPU Peak的做法,存储每个时间段的起始节点,遍历到起点加一,终点减一,if peak >= 3即为非法。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容