题目描述:
    image.png
    输入输出Demo:
    image.png
    height中的数字对应着一个柱形图:横坐标是height数字的索引值 +1;高度是height数组中的数字;求的是这些柱形图中最大矩形的面积
    image.png
    解析:在LeetCode上本题属于Medium难度。这道题也是一道典型的动态规划题目,本题属于高频题!!

    1. //双指针
    2. class Solution {
    3. public int maxArea(int[] height) {
    4. if (height.length == 0) {
    5. return 0;
    6. }
    7. int left = 0, right = height.length - 1;
    8. int maxArea = 0;
    9. while (left < right) {
    10. int currArea=(right-left)*Math.min(height[left],height[right]);
    11. maxArea=Math.max(currArea,maxArea);
    12. if(height[left] <= height[right]){
    13. left++;
    14. }else{
    15. right--;
    16. }
    17. }
    18. return maxArea;
    19. }
    20. }