<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      [leetcode] The Skyline Problem

       O(n^2) solution: Sweep

          public List<List<Integer>> getSkyline(int[][] buildings) {
              TreeSet<Integer> edgeSet = new TreeSet<>();
              for(int[] building : buildings){
                  edgeSet.add(building[0]);
                  edgeSet.add(building[1]);
              }
              List<Integer> positions = new ArrayList<>(edgeSet);
              Collections.sort(positions);
              
              List<List<Integer>> res = new ArrayList<>();
              int maxHeight, left, right, height;
              
              for(int position : positions){
                  maxHeight = 0;
                  
                  for(int[] building: buildings){
                      left = building[0];
                      right = building[1];
                      height = building[2];
                      
                      if(left<=position && position < right){
                          maxHeight = Math.max(maxHeight, height);
                      }
                  }
                  
                  if(res.isEmpty() || res.get(res.size()-1).get(1) != maxHeight){
                      res.add(Arrays.asList(position, maxHeight));
                  }
                  
              }
              
              return res;
          }
      

        

       

       O(nlogn) solution: sweep + PQ/BST

      class Solution {
          public List<int[]> getSkyline(int[][] buildings) {
              List<int[]> res = new ArrayList<>();
              List<int[]> height = new ArrayList<>();
              for (int[] building : buildings) {
                  // start point has negative height value
                  height.add(new int[]{building[0], -building[2]});
                  // end point has normal height value
                  height.add(new int[]{building[1], building[2]});
              }
              Collections.sort(height, new Comparator<int[]>() {
                  @Override
                  public int compare(int[] a, int[] b) {
                      if (a[0] == b[0]) {
                          return a[1] - b[1];
                      } else {
                          return a[0] - b[0];
                      }
                  }
              });
              // Use a maxHeap to store possible heights
              // But priority queue does not support remove in lgn time
              // treemap support add, remove, get max in lgn time, so use treemap here
              // key: height, value: number of this height
              TreeMap<Integer, Integer> pq = new TreeMap<>();
              pq.put(0, 1);
              // Before starting, the previous max height is 0;
              int prev = 0;
              // visit all points in order
              for (int[] h : height) {
                  // a start point, add height
                  if (h[1] < 0) {
                      pq.put(-h[1], pq.getOrDefault(-h[1], 0) + 1);
                  } else {  // a end point, remove height
                      if (pq.get(h[1]) > 1) {
                          pq.put(h[1], pq.get(h[1]) - 1);
                      } else {
                          pq.remove(h[1]);
                      }
                  }
                  int cur = pq.lastKey();
                  // compare current max height with previous max height, update result and 
                  // previous max height if necessary
                  if (cur != prev) {
                      res.add(new int[]{h[0], cur});
                      prev = cur;
                  }
              }
              return res;
          }
      }
      

       

      https://www.youtube.com/watch?v=GSBLe8cKu0s 

      https://leetcode.com/problems/the-skyline-problem/discuss/61193/Short-Java-solution

       

      posted @ 2022-11-02 01:55  jdflyfly  閱讀(24)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 日韩不卡一区二区在线观看| 一本之道高清乱码少妇| 亚洲一区二区中文av| 成人影片麻豆国产影片免费观看| 国产精品色一区二区三区| 乱中年女人伦av三区| 蜜桃av亚洲第一区二区| 中文字幕国产日韩精品| 在线a级毛片无码免费真人| 亚洲精品无码高潮喷水A| 中文字幕波多野不卡一区| 亚洲欧洲日产国无高清码图片| 亚洲国产成人av毛片大全| 国产精品性色一区二区三区| 久久精品无码免费不卡| 40岁大乳的熟妇在线观看| 在线观看精品日本一区二| 成人嫩草研究院久久久精品| 亚洲午夜久久久久久噜噜噜| 亚洲成人av在线高清| 97成人碰碰久久人人超级碰oo| 欧洲人与动牲交α欧美精品| 久久96热在精品国产高清| 免费视频欧美无人区码| 皋兰县| 亚洲中文精品一区二区| 国产内射性高湖| 亚洲AV蜜桃永久无码精品 | 亚洲色婷婷一区二区| 国产亚洲欧美日韩俺去了| 欧美肥老太牲交大战| 粗大的内捧猛烈进出小视频| 日本伊人色综合网| 欧美精品国产综合久久| 黑人玩弄人妻中文在线| 男女猛烈激情xx00免费视频| 四虎成人在线观看免费| 亚洲一本大道在线| 97久久超碰国产精品2021| 久爱无码精品免费视频在线观看| 奇米777四色在线精品|