fghkj

gh
mail@pastecode.io avatar
unknown
c_cpp
a year ago
824 B
1
Indexable
Never
class Solution {
public:
    int maxPoints(vector<vector<int>>& points) {
        int ans =  0;
        int n = points.size()-1;  
        
        int res = 0;

        for(int i = 0; i< n; i++){
           
            unordered_map<double, int> mp;
            for(int j = i+1; j<= n; j++){
                if(i == j) continue;
                double y = (points[i][1]-points[j][1]);
                double x = (points[i][0]-points[j][0]);
                double slope;
                if(x<0){
                    slope = INT_MAX;
                }
                else{
                    slope = y/x;
                }                
                mp[abs(slope)]++;
                ans = max(ans, mp[slope]);
            }
           
        }
        return ans+1;

  


    }
};