When I first read the question, the idea of "hough transform" pops out. I wrote my solution using this idea, but I get a TLE. As you may see, the complexity of Hough transform is only O(180N), which is much lower than those O(N^2) solutions in this discussion board.

I expected to see a "wrong answer" error, because "hough transform" has the parameter theta ( in polar coordinates ): you may have to sample the entire theta space and thus get an approximate result instead of an accurate one. Anyway, I guess some of you might be interested in knowing this classic pattern recognition algorithm.

```
#define computeRho( pt, T ) ( ( pt.x * cos( T ) ) + ( pt.y * sin( T ) ) )
class Solution {
public:
int maxPoints(vector<Point> &points) {
if ( points.size() <= 2 ) {
return points.size();
}
int max_points = 0;
for ( int i = 0; i < 180; i++ ) {
double theta = double( i ) / 180.0 * 3.141592657;
map<int,int> accumulator;
for ( int j = 0; j < points.size(); j++ ) {
int rho = round( computeRho( points[j], theta ) );
accumulator[ rho ]++;
if ( accumulator[ rho ] > max_points ) {
max_points = accumulator[ rho ];
}
}
}
return max_points;
}
};
```