Re: [閒聊] 每日leetcode

作者: dont   2024-10-12 08:10:05
2406. Divide Intervals Into Minimum Number of Groups
## 思路
昨天的簡單版
把intervals轉成新的times (left/right+1 ,state)
sort後掃一遍, 記錄重疊intertals個數的最大值
## Code
```python
class Solution:
def minGroups(self, intervals: List[List[int]]) -> int:
times = []
for left, right in intervals:
times.append((left, 1))
times.append((right+1, -1))
times.sort()
res = curr = 0
for _, delta in times:
curr += delta
res = max(res, curr)
return res
```
作者: sustainer123 (caster)   2024-10-12 08:14:00
大師 以後養我

Links booklink

Contact Us: admin [ a t ] ucptt.com