• + 0 comments

    Python

    def largestRectangle(h):
        if not len(h) > 0: return 0 
        areaMax = 0
        
        for i in range(len(h)):
            ht = h[i]
            le = i
            ri = i
            while(0 < le and h[le - 1] >= ht): le = le - 1
            while(ri < len(h) and h[ri] >= ht): ri = ri + 1
            areaMax = max(areaMax, ht * (ri - le))
        
        return areaMax