1 /**2 * Definition for a point.3 * struct Point {4 * int x;5 * int y;6 * Point (): X (0), y (0) {}7 * Point (int a, int b): X (a), Y (b) {}8 * };9 */Ten classSolution { One Public: A /** - * @param points an array of point - * @return an integer the */ - intMaxpoints (vector<point>&points) { - //Write Your code here -unordered_map<float,int>Slopes; + intMAXP =0, n =points.size (); - for(inti =0; I < n; i++) { + slopes.clear (); A intDuplicate =1; at for(intj = i +1; J < N; J + +) { - if(points[i].x = = points[j].x && Points[i].y = =points[j].y) { -duplicate++; - Continue; - } - floatSlope = (points[i].x = = points[j].x)?Int_max: in(float) (POINTS[I].Y-POINTS[J].Y)/(Points[i].x-points[j].x); -slopes[slope]++; to } +MAXP =Max (MAXP, duplicate); - for(auto slope:slopes) the if(Slope.second + Duplicate >Maxp) *MAXP = Slope.second +Duplicate; $ }Panax Notoginseng returnMaxp; - } the};
[Lintcode] Maximum number of points in a straight line