"Starting from 0 to make LeetCode" window, monotonous stack
1. The window
is solved with a doubly linked list
2. Window application: generate an array of window maximum values
3. Window application: the maximum value minus the minimum value less than or equal to the number of sub-arrays of num
Note: the sub-arrays are continuous
Violent solution:
optimal solution:
general idea: expand to the right
4. monotonic stack
Time complexity: O(N)
to find the big, from the bottom of the stack to the top of the stack, from the big
to the small to find the small, from the bottom of the stack to the top of the stack, from small to big
Find out the projects spark, hadoop that are the nearest to the right and the nearest to the left is larger than this number
, build projects, and distributed computing
5. Monotonic stack application: MaxTree
large root heap to construct an array :
Time complexity: O(N)
Monotonic stack:
6. Monotonic stack application: find the size of the largest sub-matrix
Find the largest rectangle in the histogram
First settle the elements of the popped stack during the traversal, and then settle the remaining elements in the traversal stack.
For the original problem , you only need to call a histogram for each row. The whole process is over
7. Monotonic stack applications: craters, beacon, The logarithm of mutual seeing.
If each mountain is not equal in height, that is, there is no same value.
Proof:
Advanced: The same height appears. It is great to use monotonous stacks
. This question
- Take the largest base, traverse, and settle the popped C k 2 + 2 k C_k^2+2kCk2+2 k
- After traversing, finally settle the remaining in the stack
- The third from the bottom and above, the general formula remains unchanged C k 2 + 2 k C_k^2+2kCk2+2 k
- The second to last one, if the number of occurrences at the bottom is greater than or equal to 2, C k 2 + 2 k C_k^2+2kCk2+2 k , if it is 1,C k 2 + k C_k^2+kCk2+k
- The last one, C k 2 C_k^2Ck2
Processing circular arrays
Change the next index of the circular array
C times 2 C_{times}^2Ctimes2
Deal with the rest of the last stack