nikunjsoni

149

Jun 22nd, 2021
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int maxPoints(vector<vector<int>>& points) {
  4.         int max_freq = INT_MIN;
  5.         if(points.size() == 1)
  6.             return 1;
  7.         for(int i=1; i<points.size(); i++){
  8.             unordered_map<double, int> A;
  9.             for(int j=0; j<i; j++){
  10.                 double slope;
  11.                 if(points[j][0] == points[i][0])
  12.                     slope = INT_MAX;
  13.                 else
  14.                     slope = (double)(points[i][1]-points[j][1])/(points[i][0]-points[j][0]);
  15.                 A[slope]++;
  16.                 max_freq = max(max_freq, A[slope]);
  17.             }
  18.         }
  19.         return max_freq+1;
  20.     }
  21. };
Advertisement
Add Comment
Please, Sign In to add comment