Beat 100% with C++ 4ms

  • 0
    #define FMAX 10000
    class Solution {
        int maxPoints(vector<Point>& p) {
            int n = p.size();
            float t[n][n];
            for(int i=0; i<n-1; i++)
                for(int j=i+1; j<n; j++){
                    t[i][j] = (p[i].x!=p[j].x)?(p[i].y-p[j].y)/float(p[i].x-p[j].x):(p[i].y!=p[j].y)?FMAX:-FMAX;
            int ret=0;
            for(int i=0; i<n; i++){
                int j = i+1;
                sort(t[i]+j, t[i]+n);
                int same=1;
                int best=0, last=0;
                auto cur = t[i][j];
                for(;j<n; j++){
                    last = (t[i][j]==cur)?(best=max(best,++last)),last:(cur=t[i][j],1);
                ret = max(ret, best+same);
            return ret;

Log in to reply

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