You are viewing a single comment's thread. Return to all comments →
Here's a ruby implementation:
def largestRectangle(h) max, stack = 0, [[h[0],0]] for i in 1...h.size if h[i]>h[i-1] stack.push [h[i],i] else l2=nil while stack.any? and stack[-1][0]>h[i] l = stack.pop l2 = l[1] max = [max, l[0]*(i-l[1])].max end stack.push [h[i], l2 ? l2 : i] end end stack.each{|b| max = [max, b[0]*(h.size-b[1])].max} max end
Seems like cookies are disabled on this browser, please enable them to open this website
Largest Rectangle
You are viewing a single comment's thread. Return to all comments →
Here's a ruby implementation: