Leetcode Largest Rectangle in Histogram
This question is definitely a challenge. I had a lot of worship and thought for an hour. I went online for a night. After learning, we will share the following records. Specify a histogram to find the maximum area of the rectangle. Example: 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 = [,]. the largest rectangle is shown in the shaded area, which has area = 10 unit. for example, Given height = [2, 1, 5, 6, 2, 3], return 10. the intuitive idea is that each box is the highest, and the current box can be found on both sides of the left and right. The length of the span. Record the maximum value. This is nparty's. I won't even try it. Because it definitely times out. Is there any better. Yes. Pruning: although the worst side is n, it saves a lot of computation, and the AC can select the right boundary for a Pruning (Pruning ). When height [k]> = height [k-1], no matter what the left boundary is, selecting height [k] is always larger than selecting height [k-1. Therefore, when selecting the right boundary, first find a k of height [k]