File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -42,24 +42,29 @@ public class _149 {
42
42
*/
43
43
public static class Solution1 {
44
44
public int maxPoints (int [][] points ) {
45
- if (points .length < 3 ) return points .length ;
45
+ if (points .length < 3 ) {
46
+ return points .length ;
47
+ }
46
48
int max = 0 ;
47
49
Map <Long , Integer > map = new HashMap <>();
48
50
for (int i = 0 ; i < points .length ; i ++) {
49
51
int dup = 1 ;
50
52
map .clear ();
51
53
for (int j = i + 1 ; j < points .length ; j ++) {
52
- int dx = points [j ][0 ] - points [i ][0 ], dy = points [j ][1 ] - points [i ][1 ];
53
- if (dx == 0 && dy == 0 ) dup ++;
54
- else {
54
+ int dx = points [j ][0 ] - points [i ][0 ];
55
+ int dy = points [j ][1 ] - points [i ][1 ];
56
+ if (dx == 0 && dy == 0 ) {
57
+ dup ++;
58
+ } else {
55
59
int gcd = getGcd (dx , dy );
56
60
long slope = ((long ) (dy / gcd ) << 32 ) + (dx / gcd );
57
61
map .put (slope , map .getOrDefault (slope , 0 ) + 1 );
58
62
}
59
63
}
60
64
max = Math .max (max , dup );
61
- for (Map .Entry <Long , Integer > entry : map .entrySet ())
65
+ for (Map .Entry <Long , Integer > entry : map .entrySet ()) {
62
66
max = Math .max (max , entry .getValue () + dup );
67
+ }
63
68
}
64
69
return max ;
65
70
}
You can’t perform that action at this time.
0 commit comments