fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static List<int[]> getSkyline(int[][] buildings) {
  11. List<int[]> res = new ArrayList<>();
  12.  
  13. PriorityQueue<int[]> heights = new PriorityQueue<>(buildings.length * 2, new Comparator<int[]>() {
  14. @Override
  15. public int compare(int[] o1, int[] o2) {
  16. if (o1[0] == o2[0]) {
  17. return o1[1] - o2[1];
  18. } else {
  19. return o1[0] - o2[0];
  20. }
  21. }
  22. });
  23.  
  24. for (int[] h : buildings) {
  25. heights.add(new int[]{h[0], -h[2]});
  26. heights.add(new int[]{h[1], h[2]});
  27. }
  28.  
  29.  
  30. while (heights.size() != 0) {
  31. int[] height = heights.poll();
  32. System.out.println(Arrays.toString(height));
  33. }
  34.  
  35. return res;
  36. }
  37.  
  38. public static void main(String[] args) {
  39. getSkyline(new int[][]{{0, 2, 3}, {2, 5, 3}});
  40.  
  41. }
  42.  
  43. }
Success #stdin #stdout 0.09s 320576KB
stdin
Standard input is empty
stdout
[0, -3]
[2, -3]
[2, 3]
[5, 3]