const double INF=1E9;
class Solution {
public:
int maxPoints(vector<Point> &points) {
if(points.size()==0)
return 0;
unordered_map<float,int>mp;
int res=1;
for(int i=0;i<points.size()-1;i++)
{
mp.clear();
int dup=0;
int ans=1;
for(int j=i+1;j<points.size();j++)
{
int deltax=points[j].x-points[i].x;
int deltay=points[j].y-points[i].y;
if(!deltax&!deltay)
dup++;
else
if(!deltax)
{
if(mp.find(INF)==mp.end())
mp[INF]=2;
else
mp[INF]=mp[INF]+1;
ans=max(ans,mp[INF]);
}
else
{
float k=1.0*deltay/deltax;
if(mp.find(k)==mp.end())
mp[k]=2;
else
mp[k]=mp[k]+1;
ans=max(ans,mp[k]);
}
}
res=max(res,ans+dup);
}
return res;
}
};
max points on a line
最新推荐文章于 2021-06-24 01:03:29 发布