# Python solution based on liuyifly06's link

• ``````class Solution(object):
def getSkyline(self, buildings):
"""
:type buildings: List[List[int]]
:rtype: List[List[int]]
"""
# x can only be lefts or rights
Xs = []
for l, r, _ in buildings:
Xs.append(l)
Xs.append(r)
Xs.sort()
# maxheap to store heights and rights
result, heap, i = [], [], 0
for x in Xs:
# remove ended max buildings to reveal current max building
while heap and heap[0][1] <= x:
heapq.heappop(heap)
while i < len(buildings) and buildings[i][0] == x:
heapq.heappush(heap, (-buildings[i][2], buildings[i][1]))
i += 1
# y is either 0 or max height
y = 0 if not heap else -heap[0][0]
# if y differs
if not result or result[-1][1] != y:
result.append([x, y])
return result
``````

My solution based on liuyifly06's link: https://briangordon.github.io/2014/08/the-skyline-problem.html. Thanks!

• This question is actually highly similar with 239.

• what is big-O complexity of your code?

• @DPpanic n*logn. To sort Xs and
maintain heap. n is Len(Xs).

• @pushazhiniao got it.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.