The idea is the same with https://leetcode.com/discuss/37736/108-ms-17-lines-body-explained. Thanks, StefanPochmann!
def getSkyline(self, buildings): events = sorted(buildings + [[b, float("inf"), 0] for b in buildings]) skyline, curb = , [(0, float("inf"))] for L, R, H in events: top = curb while curb<= L: heapq.heappop(curb) if H > 0: heapq.heappush(curb,(-H, R)) if top != curb: if skyline and L == skyline[-1]: skyline[-1] = -curb else: skyline.append([L, -curb]) return skyline
Very nice. But try
for L, R, H in events: (or
for left, right, height in events:), for better readability (yeah, I should have done something like that in my solution as well, probably didn't because I was translating too closely from C++).