23.01.28 Today’s Leetcode
352. Data Stream as Disjoint Intervals (hard)
왜 heapq로 maxheap, minheap 구현이 안되는지 잘모르겠다. 구악.
class SummaryRanges:
def __init__(self):
self.interval = set()
def addNum(self, value: int) -> None:
self.interval.add(value)
def getIntervals(self) -> List[List[int]]:
arr = list(self.interval)
arr.sort()
n = len(self.interval)
temp = []
i = 0
while i < n:
j = i + 1
while j < n and arr[j] - arr[j - 1] == 1:
j += 1
temp.append([arr[i], arr[j - 1]])
i = j
# print(temp)
return temp
# Your SummaryRanges object will be instantiated and called as such:
# obj = SummaryRanges()
# obj.addNum(value)
# param_2 = obj.getIntervals()