1
var getSkyline = function (buildings) {
2
let results = [];
3

4
let points = [];
5

6
for (let building of buildings) {
7
points.push([building[0], building[2]]);
8
points.push([building[1], -building[2]]);
9
}
10

11
let heights = [];
12

13
points.sort((a, b) => b[1] - a[1]);
14
points.sort((a, b) => a[0] - b[0]);
15

16
for (let point of points) {
17
if (point[1] > 0) {
18
heights.push(point[1]);
19
} else {
20
heights.splice(heights.indexOf(-point[1]), 1);
21
}
22
let curHeight = heights.length == 0 ? 0 : Math.max(...heights);
23

24
if (results.length == 0 || results[results.length - 1][1] != curHeight)
25
results.push([point[0], curHeight]);
26
}
27

28
return results;
29
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0