We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e3671b1 commit 1837ee9Copy full SHA for 1837ee9
solution/0149.Max Points on a Line/Solution.java
@@ -0,0 +1,27 @@
1
+class Solution {
2
+ public int maxPoints(Point[] points) {
3
+ if( points.length <= 2 ) return points.length;
4
+ int max = 2 ;
5
+ for( int i = 0 ; i < points.length ; i++ ){
6
+ int samePosition = 0;
7
+ int sameSlope = 1;
8
+ for( int j = i + 1 ; j < points.length ; j++ ){
9
+ long x1 = points[j].x - points[i].x;
10
+ long y1 = points[j].y - points[i].y;
11
+ if( x1 == 0 && y1 == 0 ){
12
+ samePosition++;
13
+ } else {
14
+ sameSlope++;
15
+ for(int k = j + 1 ; k < points.length ; k++ ){
16
+ long x2 = points[k].x - points[i].x;
17
+ long y2 = points[k].y - points[i].y;
18
+ if ( x1 * y2 == x2 * y1 ) sameSlope++;
19
+ }
20
21
+ if(max < (samePosition + sameSlope)) max = samePosition + sameSlope;
22
+ sameSlope = 1;
23
24
25
+ return max;
26
27
+}
0 commit comments