My Calendar III
class MyCalendarThree(object):
"""
Implement a MyCalendarThree class to store your events. A new event can always be added.
Your class will have one method, book(int start, int end). Formally, this represents a booking on the half open interval [start, end), the range of real numbers x such that start <= x < end.
A K-booking happens when K events have some non-empty intersection (ie., there is some time that is common to all K events.)
For each call to the method MyCalendar.book, return an integer K representing the largest integer such that there exists a K-booking in the calendar.
Your class will be called like this: MyCalendarThree cal = new MyCalendarThree(); MyCalendarThree.book(start, end)
""" def __init__(self):
import collections
self.delta = collections.Counter() def book(self, start, end):
"""
注意 这种方式 求的是里面重复的最大的次数,而不是最后一次加入的日历和前面重复的最大次数,
:param start:
:param end:
:return:
:param start:
:param end:
:return:
"""
self.delta[start] += 1
self.delta[end] -= 1 active = ans = 0
for x in sorted(self.delta):
if x > end:
break
active += self.delta[x]
if active > ans:
ans = active
print(active,ans)
print("-------")
return ans s = MyCalendarThree()
r1 = s.book(1, 3)
r2 = s.book(2, 4)
r3 = s.book(5, 6)
# r4 = s.book(2, 7)
# r5 = s.book(5, 10)
# print(r1, r2, r3,r4,r5)
print(r3)
My Calendar III的更多相关文章
- 【LeetCode】732. My Calendar III解题报告
[LeetCode]732. My Calendar III解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/my-calendar ...
- [LeetCode] 729. My Calendar I 731. My Calendar II 732. My Calendar III 题解
题目描述 MyCalendar主要实现一个功能就是插入指定起始结束时间的事件,对于重合的次数有要求. MyCalendar I要求任意两个事件不能有重叠的部分,如果插入这个事件会导致重合,则插入失败, ...
- [LeetCode] My Calendar III 我的日历之三
Implement a MyCalendarThree class to store your events. A new event can always be added. Your class ...
- [Swift]LeetCode732. 我的日程安排表 III | My Calendar III
Implement a MyCalendarThree class to store your events. A new event can always be added. Your class ...
- Segment Tree-732. My Calendar III
Implement a MyCalendarThree class to store your events. A new event can always be added. Your class ...
- 732. My Calendar III (prev)
Implement a MyCalendarThree class to store your events. A new event can always be added. Your class ...
- LeetCode 732. My Calendar III
原题链接在这里:https://leetcode.com/problems/my-calendar-iii/ 题目: Implement a MyCalendarThree class to stor ...
- LeetCode My Calendar I
原题链接在这里:https://leetcode.com/problems/my-calendar-i/description/ 题目: Implement a MyCalendar class to ...
- LeetCode 731. My Calendar II
原题链接在这里:https://leetcode.com/problems/my-calendar-ii/ 题目: Implement a MyCalendarTwo class to store y ...
随机推荐
- ubuntu终端执行shell脚本报command not found解决方法
使用sudo执行脚本报错:sudo: myshell.sh: command not found 原因:发生这种情况的原因是因为您正在尝试执行的脚本需要正确的权限 解决:执行sudo chmod a+ ...
- Codeforces Round #452 (Div. 2)-899A.Splitting in Teams 899B.Months and Years 899C.Dividing the numbers(规律题)
A. Splitting in Teams time limit per test 1 second memory limit per test 256 megabytes input standar ...
- 哈密顿绕行世界问题(dfs+记录路径)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2181 哈密顿绕行世界问题 Time Limit: 3000/1000 MS (Java/Others) ...
- SpringMVC框架学习笔记——各种异常、报错解决
1.Target runtime com.genuitec.runtime.generic.jee60 is not defined. 找到导入项目的.setting文件夹org.eclipse.ws ...
- html5 文本格式化
通常标签 <strong> 替换加粗标签 <b> 来使用, <em> 替换 <i>标签使用.然而,这些标签的含义是不同的:<b> 与< ...
- C#历年来最受欢迎功能
不定时更新翻译系列,此系列更新毫无时间规律,文笔菜翻译菜求各位看官老爷们轻喷,如觉得我翻译有问题请挪步原博客地址 本博文翻译自: http://www.dotnetcurry.com/csharp/1 ...
- [国嵌笔记][014][Mini2440安装Linux]
引导安装步骤 相关介绍: 开发板软件构成:Bootloader.嵌入式操作系统.嵌入式文件系统 JTAG接口常用于对flash等器件进行编程,常见的JTAG下载线有并口和USB接口两种 硬件连接: 1 ...
- java中强,软,弱,虚引用 以及WeakHahMap
java中强,软,弱,虚引用 以及WeakHahMap 一:强软引用: 参考:http://zhangjunhd.blog.51cto.com/113473/53092/进行分析 packa ...
- UVA 673 Parentheses Balance (栈)
题意描述: 给出一段只包含()和[]的字符串,判断是否合法,合法输出YES,不合法输出NO 规则: 1.该串为空,则合法 2.若A合法,B合法,则AB合法 3.若A合法,则(A)和[A]均合法 解题思 ...
- .22-浅析webpack源码之事件流compilation总览
呃,终于到了这地方-- newCompilation(params) { // ... this.applyPlugins("this-compilation", compilat ...