Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def getSkyline(self, buildings):
- """
- :type buildings: List[List[int]]
- :rtype: List[List[int]]
- """
- vectors = {}
- for li, ri, hi in buildings:
- vectors[li] = ([], [])
- vectors[ri] = ([], [])
- for li, ri, hi in buildings:
- vectors[li][0].append(hi)
- vectors[ri][1].append(hi)
- fringe = [0]
- skyline = []
- last_height = 0
- for x, (ups, downs) in sorted(vectors.items()):
- fringe.extend(ups)
- for e in downs:
- fringe.remove(e)
- height = max(fringe)
- if height != last_height:
- skyline.append((x, height))
- last_height = height
- return skyline
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement