https://leetcode-cn.com/problems/the-skyline-problem/
这道题跟摩天大楼类似
有序表



接下来根据第一个值进行排序
然后搞一个有序表,key就是高度, value就是这个高度出现的次数,
一个map,key是位置,value是这个位置的最大高度
只要最大高度有波动,它就是一个轮廓线产生的位置





所以答案就是拐点
ps注意:要防止纸片楼
在7位置加然后又在7位置减, 在比较器中就需要让加排在前面,减排在后面
public static class Node {public int x;public boolean isAdd;public int h;public Node(int x, boolean isAdd, int h) {this.x = x;this.isAdd = isAdd;this.h = h;}}public static class NodeComparator implements Comparator<Node> {@Overridepublic int compare(Node o1, Node o2) {if (o1.x != o2.x) {return o1.x - o2.x;}if (o1.isAdd != o2.isAdd) {return o1.isAdd ? -1 : 1;}return 0;}}public List<List<Integer>> getSkyline(int[][] buildings) {Node[] nodes = new Node[buildings.length * 2];for (int i = 0; i < buildings.length; i++) {nodes[i * 2] = new Node(buildings[i][0], true, buildings[i][2]);nodes[i * 2 + 1] = new Node(buildings[i][1], false, buildings[i][2]);}Arrays.sort(nodes, new NodeComparator());// 有序表,key 代表某个高度 value 这个高度出现的次数TreeMap<Integer, Integer> mapHeightTimes = new TreeMap<>();// 有序表 key x的值 value 处在x位置时的高度TreeMap<Integer, Integer> xMaxHeight = new TreeMap<>();for (int i = 0; i < nodes.length; i++) {if (nodes[i].isAdd) {if (!mapHeightTimes.containsKey(nodes[i].h)) {mapHeightTimes.put(nodes[i].h, 1);} else {mapHeightTimes.put(nodes[i].h, mapHeightTimes.get(nodes[i].h) + 1);}} else {if (mapHeightTimes.get(nodes[i].h) == 1) {mapHeightTimes.remove(nodes[i].h);} else {mapHeightTimes.put(nodes[i].h, mapHeightTimes.get(nodes[i].h) - 1);}}if (mapHeightTimes.isEmpty()) {xMaxHeight.put(nodes[i].x, 0);} else {xMaxHeight.put(nodes[i].x, mapHeightTimes.lastKey());}}List<List<Integer>> ans = new ArrayList<>();for (Map.Entry<Integer, Integer> entry : xMaxHeight.entrySet()) {int curx = entry.getKey();int curMaxHeight = entry.getValue();if (ans.isEmpty() || ans.get(ans.size() - 1).get(1) != curMaxHeight) {ans.add(new ArrayList<>(Arrays.asList(curx, curMaxHeight)));}}return ans;}
