#include <stdio.h>
#include <stdlib.h>
#include "string.h"
#define max(a, b) (((a) > (b)) ? (a) : (b))
int maxLen(int *heights,int heightsize){
int sum = 0;
for (int i = 0; i < heightsize; i++) {
int left = i;
int right = i;
for (; left >= 0; left--) {
if (heights[left] < heights[i]) break;
}
for (; right < heightsize; right++) {
if (heights[right] < heights[i]) break;
}
int w = right - left - 1;
int h = heights[i];
sum = max(sum, w * h);
}
printf("%d",sum);
}
int main()
{
int heights[]={2,1,5,6,2,3};
maxLen(heights,6);
return 0;
}
leetcode 柱状图中最大矩形 暴力搜索
最新推荐文章于 2024-08-17 20:25:49 发布