Re: [閒聊] 每日leetcode

看板Marginalman作者 (dont)時間1年前 (2024/10/12 08:10), 編輯推噓1(100)
留言1則, 1人參與, 1年前最新討論串976/1554 (看更多)
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 ``` -- https://i.imgur.com/kyBhy6o.jpeg
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 185.213.82.23 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1728691807.A.401.html

10/12 08:14, 1年前 , 1F
大師 以後養我
10/12 08:14, 1F
文章代碼(AID): #1d2RvVG1 (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1d2RvVG1 (Marginalman)