Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.
//提示运行时间超过限制,估计是计算斜率和逐个判断导致超时,但是目前没有想到其他好的方法。
//求大神解救~
class Solution {
public:
int maxPoints(vector
double k;
double b;
int max=0;
for(int i=0; i { for(int j=i+1; j { k=(points.at(i).y-points.at(j).y)/(points.at(i).x-points.at(j).x); b=points.at(i).y-k*points.at(i).x; int count=0; for(int p=0; p { if(points.at(p).y==k*points.at(p).x+b) count++; } if(max max=count; } } return max; } };