-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
36 lines (35 loc) · 989 Bytes
/
Solution.cs
File metadata and controls
36 lines (35 loc) · 989 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
34
35
36
public class Solution
{
public int MaxPoints(int[][] points)
{
int n = points.Length;
if (n <= 2) return n;
int maxPoints = 0;
Dictionary<(double, double), int> map = [];
for (int i = 0; i < n; i++)
{
int x1 = points[i][0], y1 = points[i][1];
for (int j = i + 1; j < n; j++)
{
int x2 = points[j][0], y2 = points[j][1];
int a = x2 - x1, b = y2 - y1;
if (a == 0)
{
map.TryAdd((0, 0), 0);
map[(0, 0)]++;
}
else
{
map.TryAdd((a / a, 1D * b / a), 0);
map[(a / a, 1D * b / a)]++;
}
}
foreach (var val in map.Values)
{
maxPoints = Math.Max(maxPoints, val);
}
map.Clear();
}
return maxPoints + 1;
}
}