64,654
社区成员
发帖
与我相关
我的任务
分享
class Solution {
public:
int maxPoints(vector<Point>& points) {
unordered_map<float,int> slopes;
int max=0;
for( int i=points.size()-1 ; i>=max ; i-- ) {
slopes.clear();
int m=0,dup=1;
for( int j=i-1 ; j>=0; j--) {
if( points[i].x == points[j].x){
if( points[i].y == points[j].y)
dup++;
else
slopes[INT_MAX]++;
}else
slopes[(float)(points[i].y-points[j].y)/(points[i].x-points[j].x)]++;
}
for( auto s : slopes)
m = m>s.second?m:s.second;
m += dup;
max = max>m?max:m;
}
return max;
}
};