leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0149.cpp (542B)


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