1
class Solution:
2
def getSkyline(self, buildings: List[List[int]]) -> List[List[int]]:
3
d = collections.defaultdict(list)
4

5
for i, (start, end, height) in enumerate(buildings):
6
d[start].append(height)
7
d[end].append(-height)
8

9
l = list(d.keys())
10
l.sort()
11

12
result = []
13

14
active = []
15

16
for key in l:
17
o = d[key]
18
o.sort(reverse=True)
19
for j in o:
20
if j > 0:
21
if not result or not active:
22
result.append([key, j])
23
active.append(j)
24
else:
25
if j > active[-1]:
26
result.append([key, j])
27
active.append(j)
28
else:
29
active.insert(bisect_left(active, j), j)
30
else:
31
idx = active.index(-j)
32
if idx == len(active) - 1:
33
active.pop()
34
if active:
35
result.append([key, active[-1]])
36
else:
37
result.append([key, 0])
38
else:
39
active.pop(idx)
40

41
return result

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0