Last active
December 5, 2016 16:03
-
-
Save TheDudeWithTheThing/75ade344782cc998f2726fb561c6482b to your computer and use it in GitHub Desktop.
My SkyLine solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SkySkraper | |
def self.area(coords) | |
area_total = 0 | |
height_at = {} | |
coords.each do |set| | |
(x1, x2, height) = set | |
range_exclude_last(x1, x2).each do |x| | |
height_at[x] ||= 0 | |
if height > height_at[x] | |
area_total += height - height_at[x] | |
height_at[x] = height | |
end | |
end | |
end | |
area_total | |
end | |
def self.range_exclude_last(x1, x2) | |
(x1..x2 - 1).to_a | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment