|
| 1 | +class Solution { |
| 2 | + public int numberOfPairs(int[][] points) { |
| 3 | + Arrays.sort(points, (o1, o2) -> { |
| 4 | + int c = o1[0] - o2[0]; |
| 5 | + if (c == 0) { |
| 6 | + return o2[1] - o1[1]; |
| 7 | + } |
| 8 | + return c; |
| 9 | + }); |
| 10 | + int result = 0; |
| 11 | + for (int i = 0; i < points.length; i++) { |
| 12 | + int[] point = points[i]; |
| 13 | + int minX = point[0] - 1; |
| 14 | + int maxX = Integer.MAX_VALUE; |
| 15 | + int minY = Integer.MIN_VALUE; |
| 16 | + int maxY = point[1] + 1; |
| 17 | + for (int j = i + 1; j < points.length; j++) { |
| 18 | + int[] nextPoint = points[j]; |
| 19 | + if (nextPoint[0] > minX && nextPoint[0] < maxX && nextPoint[1] > minY && nextPoint[1] < maxY) { |
| 20 | + result++; |
| 21 | + minX = nextPoint[0]; |
| 22 | + minY = nextPoint[1]; |
| 23 | + } |
| 24 | + } |
| 25 | + } |
| 26 | + return result; |
| 27 | + } |
| 28 | +} |
0 commit comments