fghkj
ghunknown
c_cpp
2 years ago
824 B
4
Indexable
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; } };
Editor is loading...