publicintcountCoveredBuildings(int n, int[][] buildings) { Map<Integer, int[]> rowMinMax = newHashMap<>(); Map<Integer, int[]> colMinMax = newHashMap<>(); for (int[] building : buildings) { intx= building[0], y = building[1]; rowMinMax.compute(x, (k, v) -> v == null ? newint[]{y, y} : newint[]{Math.min(v[0], y), Math.max(v[1], y)}); colMinMax.compute(y, (k, v) -> v == null ? newint[]{x, x} : newint[]{Math.min(v[0], x), Math.max(v[1], x)}); }
intans=0; for (int[] p : buildings) { intx= p[0], y = p[1]; int[] row = rowMinMax.get(x); int[] col = colMinMax.get(y); if (row[0] < y && y < row[1] && col[0] < x && x < col[1]) { ans++; } } return ans; } }