public int maxPoints(int[][] points) { if (points == null) return -1; if (points.length <= 1) return points.length; Map<String, Integer> map = new HashMap<>(); int res = 0; for (int i = 0; i < points.length; i++) { int same = 1; for (int j = 0; j < points.length; j++) { if (i == j) continue; int x = points[i][0] - points[j][0]; int y = points[i][1] - points[j][1]; if (x == 0 && y == 0) { same++; continue; } int gcd = gcd(x, y); String key = x / gcd + "-" + y / gcd; map.put(key, map.getOrDefault(key, 0) + 1); } if (map.isEmpty()) res = Math.max(res, same); else { for (int val : map.values()) res = Math.max(res, val + same); } map.clear(); } return res;}public int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y);}