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 ...
随机推荐
- codechef [snackdown2017 Onsite Final] AND Graph
传送门 题解给出了一个很强势的dp: i<K $$dp[i][len]*Fib[len+2-(t[i]==1)] -> dp[i+1][len]$$ $$dp[i][len]*Fib[le ...
- hdu_2444The Accomodation of Students(二分图的判定和计算)
hdu_2444The Accomodation of Students(二分图的判定和计算) 标签:二分图匹配 题目链接 题意: 问学生是否能分成两部分,每一部分的人都不相认识,如果能分成的话,两两 ...
- NYoj_171聪明的kk
聪明的kk 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 聪明的"KK" 非洲某国展馆的设计灵感源于富有传奇色彩的沙漠中陡然起伏的沙丘,体现出本国不 ...
- android企业级商城源码、360°全景图VR源码、全民直播源码等
Android精选源码 [新版]Android技术博客精华汇总 开源了:乐乐音乐5.0-Android音乐播放器 android实现仿真水波纹效果源码 360°全景图VR,这是一个值得把玩的APP a ...
- 拿到List<Map<String,String>>对用属性的值。。。。。。。
list.get(i).get("orderNumber") 来拿到下面的对应属性的值
- Spark性能调优之合理设置并行度
Spark性能调优之合理设置并行度 1.Spark的并行度指的是什么? spark作业中,各个stage的task的数量,也就代表了spark作业在各个阶段stage的并行度! 当分配 ...
- 怎么去掉织梦网站首页带的index.html/index.php
方法1. 1)在空间面板里面找到默认首页设置: 我们是需要去掉index.html,这时我们只需要把index.html这个把它移到最顶级去就行,然后点击确定,在打开网站刷新下,就基本可以解决了! 其 ...
- Dedecms列表页标签list/pagelist使用方法及pagelist的样式
Dede的默认页面中有个list_article.htm页面,这是dede的列表页面.在列表页显示文章的列表,是通过dede的list和pagelist这两个个标签实现的.本文就这两个标签的使用及pa ...
- vi的常用命令
https://zhidao.baidu.com/question/332242228.html vi的基本操作 a) 进入vi 在系统提示符号输入vi及文件名称后,就进入vi全屏幕编辑画面: $ v ...
- php 5.0 与7.0有什么区别
我有更好的答案 发布于2017-05-19 12:30 最佳答案 PHP7特性 PHP 7.0.0 Alpha 1[1] 使用新版的ZendEngine引擎,带来了许多新的特性,以下是不完全列表: 性 ...