1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
def assert(x, y)
raise [x, y].inspect unless x == y
end
class Solution
def self.run(buildings)
changes = []
result = []
buildings.each do |building|
left, right, height = building
left.upto(right) do |n|
changes[n] = height
end
end
current = nil
changes.each_with_index do |item, index|
next if item == current
current = item
result << [index, item]
end
result << [changes.size, 0]
result
end
end
assert Solution.run([[2,8,3], [4,6,5]]), [[2,3], [4,5], [7,3], [9,0]]
|