give me money


  • 0
    Y
    int maxPoints(vector<Point>& points) {
            if(points.size() < 2)
                return points.size();
            vector<long> dx;
            vector<long> dy;
            vector<int> cs;
            int ret=0;
            for(int i=0;i<points.size();++i)
            {
                int s = 0;
                for(int j=0;j<points.size();++j)
                {
                    if(j==i || (points[j].x == points[i].x && points[j].y == points[i].y))
                    {
                        s++;
                        if(s > ret)
                            ret = s;
                        continue;
                    }
                    long x = points[j].x-points[i].x;
                    long y = points[j].y-points[i].y;
                    int m=0;
                    for(;m<cs.size();++m)
                    {
                        if(dx[m]*y==dy[m]*x)
                        {
                            cs[m]++;
                            if(cs[m]+s > ret)
                                ret = cs[m]+s;
                            break;
                        }
                    }
                    if(m >= cs.size())
                    {
                        dx.push_back(x);
                        dy.push_back(y);
                        cs.push_back(1);
                        if(1+s > ret)
                            ret = 1+s;
                    }
                }
                dx.clear();
                dy.clear();
                cs.clear();
            }
            return ret;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.