LeetCode - Max Points on a Line
来源:互联网 发布:window版mysql如何删除 编辑:程序博客网 时间:2024/06/03 01:37
Max Points on a Line
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.
/** * 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 result = 0; for (int i = 0; i < points.size(); ++i) {std::unordered_map<string, int> number;int mx = 0;int same = 1;for (int j = i+1; j < points.size(); ++j) { int x = points[j].x - points[i].x; int y = points[j].y - points[i].y; int g = gcd(x, y); if (g !=0) { x /= g; y /= g; mx = max(mx, ++number[to_string(x) + " " + to_string(y)]); } else { same++; continue; }}result = max(result, (mx + same)); } return result; } int gcd(int a, int b) { return a? a/abs(a)*abs(gcd(b%a, a)) : b; }};
0 0
- Max Points on a Line | leetcode
- Max Points on a Line LEETCODE
- Leetcode: Max Points on a Line
- LeetCode - Max Points on a Line
- LeetCode 之 Max Points on a Line
- LeetCode | Max Points on a Line
- [LeetCode] Max Points on a Line
- Leetcode: Max Points on a Line
- LeetCode OJ:Max Points on a Line
- Leetcode Max Points on a Line
- Leetcode: Max Points on a Line .
- [Leetcode] Max Points on a Line (Java)
- leetcode:【Max Points on a Line】
- Max Points on a Line - LeetCode
- LeetCode:Max Points on a Line
- [LeetCode] Max Points on a Line
- leetcode - Max Points on a Line
- LeetCode(149)Max Points on a Line
- SWAT 学习相关基础知识(一)---Mr.Zhang
- JMS调用QueueConnection.close连接关闭代码但是实际未关闭
- php中获取系统信息的方法
- css设置强制文字不换行,多用于表格单元格格式
- MySQL 存储过程参数用法 in, out, inout
- LeetCode - Max Points on a Line
- Phone format 正则表达式
- JQuery选择器2
- 网页设计常用色彩搭配表 – 配色表
- Make Menuconfig简介
- java(18) - 枚举类型和静态导入
- SharePoint 2013 对二进制大型对象(BLOB)进行爬网
- SharePoint 2013 图文开发系列之WebPart
- Android Socket通信例子