-
Notifications
You must be signed in to change notification settings - Fork 56
/
Solution.java
28 lines (26 loc) · 974 Bytes
/
Solution.java
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
package g0101_0200.s0149_max_points_on_a_line;
// #Hard #Top_Interview_Questions #Array #Hash_Table #Math #Geometry #Algorithm_II_Day_21_Others
// #2022_06_24_Time_11_ms_(99.21%)_Space_41.5_MB_(95.53%)
public class Solution {
public int maxPoints(int[][] points) {
if (points.length < 2) {
return points.length;
}
int max = 0;
for (int i = 0; i < points.length; i++) {
for (int j = i + 1; j < points.length; j++) {
int x = points[j][0] - points[i][0];
int y = points[j][1] - points[i][1];
int c = x * points[j][1] - y * points[j][0];
int count = 2;
for (int k = j + 1; k < points.length; k++) {
if (c == x * points[k][1] - y * points[k][0]) {
count++;
}
}
max = Math.max(count, max);
}
}
return max;
}
}