-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
/
Copy pathSolution.java
27 lines (27 loc) · 1015 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
class Solution {
public int maxPoints(Point[] points) {
if( points.length <= 2 ) return points.length;
int max = 2 ;
for( int i = 0 ; i < points.length ; i++ ){
int samePosition = 0;
int sameSlope = 1;
for( int j = i + 1 ; j < points.length ; j++ ){
long x1 = points[j].x - points[i].x;
long y1 = points[j].y - points[i].y;
if( x1 == 0 && y1 == 0 ){
samePosition++;
} else {
sameSlope++;
for(int k = j + 1 ; k < points.length ; k++ ){
long x2 = points[k].x - points[i].x;
long y2 = points[k].y - points[i].y;
if ( x1 * y2 == x2 * y1 ) sameSlope++;
}
}
if(max < (samePosition + sameSlope)) max = samePosition + sameSlope;
sameSlope = 1;
}
}
return max;
}
}