We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 89a75cf commit 4bbca01Copy full SHA for 4bbca01
python/the_skyline_problem.py
@@ -0,0 +1,25 @@
1
+import bisect
2
+
3
+class Solution:
4
+ def getSkyline(self, buildings):
5
+ h = []
6
+ for b in buildings:
7
+ h.append((b[0], -b[2]))
8
+ h.append((b[1], b[2]))
9
10
+ h.sort()
11
+ prev = cur = 0
12
+ m = [0]
13
+ res = []
14
15
+ for i in h:
16
+ if i[1] < 0:
17
+ bisect.insort(m, -i[1])
18
+ else:
19
+ m.remove(i[1])
20
+ cur = max(m)
21
+ if cur != prev:
22
+ res.append([i[0], cur])
23
+ prev = cur
24
25
+ return res
0 commit comments