<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    IT技術小屋

    秋風秋雨,皆入我心

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      38 隨筆 :: 1 文章 :: 19 評論 :: 0 Trackbacks
    Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.
    Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3].
    The largest rectangle is shown in the shaded area, which has area = 10 unit.
    For example,
    Given height = [2,1,5,6,2,3],
    return 10.

    本題需要使用棧維護一個高度單調遞增的序列下標,如果遇到一個元素比當前棧頂元素高度小,那么出棧,并計算當前最大面積。如果棧為空,需要特殊考慮。
     1 public class LargestRectangleinHistogram {
     2     public int largestRectangleArea(int[] height) {
     3         Stack<Integer> stack = new Stack<Integer>();
     4         int i = 0;
     5         int maxArea = 0;
     6         int[] h = new int[height.length + 1];
     7         h = Arrays.copyOf(height, height.length + 1);
     8         while (i < h.length) {
     9             if (stack.isEmpty() || h[stack.peek()] <= h[i]) {
    10                 stack.push(i++);
    11             } else {
    12                 int t = stack.pop();
    13                 maxArea = Math.max(maxArea, h[t] * (stack.isEmpty() ? i : i - stack.peek() - 1));
    14             }
    15         }
    16         return maxArea;
    17     }
    18 }
    posted on 2014-01-05 12:31 Meng Lee 閱讀(275) 評論(0)  編輯  收藏 所屬分類: Leetcode
    主站蜘蛛池模板: 免费乱理伦在线播放| 扒开双腿猛进入爽爽免费视频| 亚洲AV无码成H人在线观看 | 亚洲国产成人资源在线软件| 麻豆精品成人免费国产片| 亚洲免费观看视频| a级毛片高清免费视频就| 中文字幕亚洲综合久久菠萝蜜| 乱淫片免费影院观看| 国产成人毛片亚洲精品| 羞羞视频免费网站在线看| 国产性爱在线观看亚洲黄色一级片| 香港经典a毛片免费观看看| 亚洲另类无码一区二区三区| 成人免费午夜无码视频| 亚洲日韩欧洲乱码AV夜夜摸| a级毛片免费在线观看| 亚洲日本精品一区二区| 69式国产真人免费视频| 亚洲乱色伦图片区小说| 国产一级高清视频免费看| xxxxx做受大片视频免费| 亚洲国产综合无码一区 | 亚洲综合欧美色五月俺也去| 最近2019中文字幕mv免费看| 男女猛烈xx00免费视频试看| 爱情岛论坛网亚洲品质自拍| 免费无码作爱视频| 亚洲国产综合人成综合网站00| 在线jlzzjlzz免费播放| 一级毛片免费不卡直观看| 亚洲视频在线免费观看| 午夜影视在线免费观看| 一个人看的在线免费视频| 亚洲视频精品在线观看| 一区二区3区免费视频| 亚洲尹人九九大色香蕉网站| 日本一区二区三区日本免费| 在线观看肉片AV网站免费| 亚洲综合av一区二区三区| 亚洲天堂免费在线视频|