-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
33 lines (32 loc) · 901 Bytes
/
Solution.cs
File metadata and controls
33 lines (32 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public class Solution
{
public int NumberOfPairs(int[][] points)
{
int count = 0;
Array.Sort(points, (a, b) =>
{
if (a[0] == b[0]) return b[1] - a[1];
return a[0] - b[0];
});
int n = points.Length;
for (int i = 0; i < n - 1; i++)
{
int[] pointA = points[i];
int xMin = pointA[0] - 1;
int xMax = int.MaxValue;
int yMin = int.MinValue;
int yMax = pointA[1] + 1;
for (int j = i + 1; j < n; j++)
{
int[] pointB = points[j];
if (pointB[0] > xMin && pointB[0] < xMax && pointB[1] > yMin && pointB[1] < yMax)
{
count++;
xMin = pointB[0];
yMin = pointB[1];
}
}
}
return count;
}
}