LeetCode 84

Description

Given n non-negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.

Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3].

The largest rectangle is shown in the shaded area, which has area = 10 unit.

Example:

Solution

$$height = (1, 2, 4, 5, 8, 10)$$

$$ans = \mathop{\arg \max}_{1\leq i\leq n} h[i] \times (n - i + 1)​$$

Python Code:

LeetCode 85

Description

Given a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing only 1’s and return its area.

Example:

Solution

Python Code：

------ 本文结束------
0%