I. Specific questions: Give a set of non-negative integers to represent a bar chart. design an algorithm to obtain the area of the largest rectangle in the bar chart. For example, enter the following data:, and. Each number indicates the height of a column. If the width of a column is 1 by default, the area of the maximum rectangle is 10.
==>
This problem exists in leetcode: largest rectangle in Histogram
Algorithm time complexity O (n ):
Int largestrectarea (vector <int> & height) {stack <int> P; int I = 0, Res = 0; height. push_back (0); // function: Clear the stack while (I
2. Find the largest White Rectangle in a single map: Give You A nxn black/white bitmap to find the largest White Rectangle. Note that it is a rectangle, not any white area.
If we use the largest sub-array and the solution, the complexity is O (n ^ 3). In fact, we can use the above algorithm to solve the problem:
Chen liren: This is actually a variant of the above question "finding the largest rectangle from the bar chart. Basic Idea: scan the number of white points in each column on the row in the unit of behavior, and record them into an array similar to a bar chart. Consider the previous results, this can be O (N). Then, use the solution O (n) of the question to obtain the largest rectangle. Therefore, the complexity of the entire algorithm is O (n * n ). It is important for children to learn what they have learned.