private static int maxPoints(Point[] points){
  if (points.length < 3)   return points.length;
  int res=1;
  Map<String,Integer> map=new HashMap<String,Integer>();
  for (int i=0; i < points.length; i++) {
    int max=0;
    int countSame=0;
    for (int j=i + 1; j < points.length; j++) {
      if (points[i].x == points[j].x && points[i].y == points[j].y)       countSame++;
 else {
        String key=normalize(points[i],points[j]);
        if (map.containsKey(key)) {
          int count=map.get(key) + 1;
          map.put(key,count);
          if (count > max)           max=count;
        }
 else {
          map.put(key,1);
          if (max == 0)           max++;
        }
      }
    }
    res=Math.max(res,max + countSame + 1);
    map.clear();
  }
  return res;
}

private static int maxPoints ( Point [ ] points ) { if ( points . length < 3 ) return points . length ; int res = 1 ; Map < String , Integer > map = new HashMap < String , Integer > ( ) ; for ( int i = 0 ; i < points . length ; i ++ ) { int max = 0 ; int countSame = 0 ; for ( int j = i + 1 ; j < points . length ; j ++ ) { if ( points [ i ] . x == points [ j ] . x && points [ i ] . y == points [ j ] . y ) countSame ++ ; else { String key = normalize ( points [ i ] , points [ j ] ) ; if ( map . containsKey ( key ) ) { int count = map . get ( key ) + 1 ; map . put ( key , count ) ; if ( count > max ) max = count ; } else { map . put ( key , 1 ) ; if ( max == 0 ) max ++ ; } } } res = Math . max ( res , max + countSame + 1 ) ; map . clear ( ) ; } return res ; }
set a point and go through the rest use max to record the max points of current loop use countsame to track the number of points use result to track the max points use a map to store lines , key is the feature of the line , value is the number of points
