做一个内容网站多少钱,济南网站建设 选搜点o,和wordpress类似,江都微信网站建设84.柱状图中最大的矩形
1、题目链接#xff1a;. - 力扣#xff08;LeetCode#xff09;
2、文章讲解#xff1a;代码随想录
3、题目#xff1a;
给定 n 个非负整数#xff0c;用来表示柱状图中各个柱子的高度。每个柱子彼此相邻#xff0c;且宽度为 1 。
求在该柱…84.柱状图中最大的矩形
1、题目链接. - 力扣LeetCode
2、文章讲解代码随想录
3、题目
给定 n 个非负整数用来表示柱状图中各个柱子的高度。每个柱子彼此相邻且宽度为 1 。
求在该柱状图中能够勾勒出来的矩形的最大面积。 1 heights.length 10^50 heights[i] 10^4
4、视频链接
单调栈又一次经典来袭 LeetCode84.柱状图中最大的矩形_哔哩哔哩_bilibili
int[] newHeight new int[heights.length 2];System.arraycopy(heights, 0, newHeight, 1, heights.length);newHeight[heights.length1] 0;newHeight[0] 0;StackInteger stack new Stack();stack.push(0);int res 0;for (int i 1; i newHeight.length; i) {while (newHeight[i] newHeight[stack.peek()]) {int mid stack.pop();int w i - stack.peek() - 1;int h newHeight[mid];res Math.max(res, w * h);}stack.push(i);}return res;