0149.cpp (542B)
1 class Solution { 2 public: 3 int maxPoints(vector<vector<int>> &points) { 4 int n = points.size(); 5 if (n == 1) return 1; 6 7 int res = 2; 8 for (int i = 0; i < n; i++) { 9 unordered_map<double, int> um; 10 for (int j = 0; j < n; j++) { 11 if (j == i) continue; 12 um[atan2(points[j][1] - points[i][1], points[j][0] - points[i][0])]++; 13 } 14 for (auto [_, count] : um) 15 res = max(res, count + 1); 16 } 17 return res; 18 } 19 };