代码拉取完成,页面将自动刷新
// Time: O(n^2)
// Space: O(n)
/**
* Definition for a point.
* struct Point {
* int x;
* int y;
* Point() : x(0), y(0) {}
* Point(int a, int b) : x(a), y(b) {}
* };
*/
class Solution {
public:
int maxPoints(vector<Point>& points) {
int max_points = 0;
for (int i = 0; i < points.size(); ++i) {
unordered_map<double, int> slope_count;
const auto& start = points[i];
int same = 1;
for (int j = i + 1; j < points.size(); ++j) {
const auto& end = points[j];
if (start.x == end.x && start.y == end.y) {
++same;
} else {
auto slope = numeric_limits<double>::max();
if (start.x - end.x != 0) {
slope = (start.y - end.y) * 1.0 / (start.x - end.x);
}
++slope_count[slope];
}
}
int current_max = same;
for (const auto& kvp : slope_count) {
current_max = max(current_max, kvp.second + same);
}
max_points = max(max_points, current_max);
}
return max_points;
}
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。