concise c++


  • 0
    K
    class Solution {
    public:
        int maxPoints(vector<Point>& points) {
            int res = 0;
            for (int i = 0; i < points.size(); ++i) {
                int localmax = 0, dup = 1, vertical = 1;
                unordered_map<double, int> m;
                for (int j = i + 1; j < points.size(); ++j) {
                    if (points[i].x == points[j].x && points[i].y == points[j].y) ++dup;
                    else if (points[i].x == points[j].x) ++vertical;
                    else {
                        double slope = double(points[i].y - points[j].y) / (points[i].x - points[j].x);
                        ++m[slope];
                    }
                }
                for (auto &a: m) localmax = max(a.second, localmax);
                res = max(vertical, max(localmax + dup, res));
            }
            return res;
        }
    };
    

Log in to reply
 

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