The Skyline Problem
来源:互联网 发布:快捷矩阵官网 编辑:程序博客网 时间:2024/05/04 22:28
public class Solution { public List<int[]> getSkyline(int[][] buildings) { List<int[]> res = new LinkedList<>(); List<int[]> heights = new LinkedList<>(); for (int[] b: buildings) { heights.add(new int[]{b[0], -b[2]}); heights.add(new int[]{b[1], b[2]}); } Collections.sort(heights, new Comparator<int[]>(){ @Override public int compare(int[] a, int[] b) { if (a[0] != b[0]) { return a[0] - b[0]; } else { return a[1] - b[1]; } } }); PriorityQueue<Integer> queue = new PriorityQueue<>(11, new Comparator<Integer>(){ @Override public int compare(Integer a, Integer b) { return b - a; } }); queue.offer(0); int prev = 0; for (int[] h: heights) { if (h[1] < 0) { queue.offer(-h[1]); } else { queue.remove(h[1]); } int cur = queue.peek(); if (cur != prev) { res.add(new int[]{h[0], cur}); prev = cur; } } return res; }}
0 0
- 105 - The Skyline Problem
- leetcode - The Skyline Problem
- The Skyline Problem
- The Skyline Problem
- The Skyline Problem
- LeetCode - The Skyline Problem
- leetcode:the skyline problem
- LeetCode218:The Skyline Problem
- The Skyline Problem -- leetcode
- Leetcode -- The Skyline Problem
- 218 .The Skyline Problem
- The Skyline Problem
- The Skyline Problem
- The Skyline Problem
- The Skyline Problem
- The Skyline Problem
- The Skyline Problem
- The Skyline Problem
- [leetcode] 374. Guess Number Higher or Lower 解题报告
- Gym 100637J
- Aizu 2677
- 计算获取Unity物体下面的地面的坐标点
- handler消息机制源码级深入全解析
- The Skyline Problem
- Word Ladder
- Read N Characters Given Read4 II - Call multiple times
- Subsets II
- 顶点法向量的矩阵变换
- LeetNode--No.257--Binary Tree Paths
- ${pageContext.request.contextPath} 表达式的分析及作用
- LeetCode--No.100--Same Tree
- 网络最大流 相反的方向发回一个流 选取具有最少边数的路径