1 class Solution:
 2     def maxEvents(self, events: 'List[List[int]]') -> int:
 3         events.sort(key=lambda item: (item[1], item[0]))
 4         days = set()
 5         for start, end in events:
 6             if start not in days:
 7                 days.add(start)
 8             else:
 9                 i = start + 1
10                 while i in days and i <= end:
11                     i += 1
12                 if i <= end:
13                     days.add(i)
14         return len(days)

算法思路:贪心法。

参考地址:https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended/discuss/510302/Python3-Greedy

posted on 2020-02-16 19:00  Sempron2800+  阅读(174)  评论(0编辑  收藏  举报