--- title: 149. Max Points on a Line tags: String description: share source code. --- # 149. Max Points on a Line ```java class Solution { public int maxPoints(int[][] points) { int n = points.length; int INF = Integer.MAX_VALUE; int max = 0; for(int i = 0; i < n; i++ ){ Map<String, Integer> map = new HashMap<>(); double slope = 0; for(int j = i + 1; j < n; j++ ){ if(points[i][0] - points[j][0] == 0){ slope = INF; }else if(points[i][1] - points[j][1] == 0){ slope = 0; }else{ slope = (double)(points[i][1] - points[j][1])/(points[i][0] - points[j][0]); } double intercept = points[i][1] - slope*points[i][0]; String key = slope +":" + intercept; //System.out.println( Arrays.toString(points[j]) + " key: "+slope); map.put(key, map.getOrDefault(key, 0) + 1); max = Math.max(max, map.get(key)); } } return max + 1; } }