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) {
if(points.size()<)return points.size();
int sizeMax=;
for(int i=;i<points.size();i++)
{
int repeat=;
map<double,int> smap;
smap.clear();
for(int j=;j<points.size();j++)
{
if(i==j)continue;
if(points[i].x==points[j].x&&points[i].y==points[j].y)
{
repeat++;
continue;
}
double k=points[i].x==points[j].x?INT_MAX:double(points[j].y-points[i].y)/(points[j].x-points[i].x);
smap[k]++;
}
if(smap.size()==)
{
sizeMax=sizeMax>repeat?sizeMax:repeat;
continue;
}
for(map<double,int>::iterator iter=smap.begin();iter!=smap.end();iter++)
{
sizeMax=sizeMax>(iter->second+repeat)?sizeMax:(iter->second+repeat);
}
}
return sizeMax;
}
};

leetcode[149]Max Points on a Line的更多相关文章

  1. [leetcode]149. 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. ...

  2. [LeetCode] 149. 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. ...

  3. Java for LeetCode 149 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. ...

  4. leetcode 149. Max Points on a Line --------- java

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...

  5. 【LeetCode】149. Max Points on a Line

    Max Points on a Line Given n points on a 2D plane, find the maximum number of points that lie on the ...

  6. 【leetcode】Max Points on a Line

    Max Points on a Line 题目描述: Given n points on a 2D plane, find the maximum number of points that lie ...

  7. [LeetCode OJ] Max Points on a Line

    Max Points on a Line Submission Details 27 / 27 test cases passed. Status: Accepted Runtime: 472 ms ...

  8. 【LeetCode】149. Max Points on a Line 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典+最大公约数 日期 题目地址:https://l ...

  9. 149. Max Points on a Line

    题目: Given n points on a 2D plane, find the maximum number of points that lie on the same straight li ...

随机推荐

  1. 使用jquery模拟键盘事件,但window系统并不会真的响应事件,只是浏览器当前页面会响应而已

    <!DOCTYPE html> <html> <head> <title>Demo</title> <meta http-equiv= ...

  2. SMB/CIFS协议解析

    1.SMB协议与CIFS协议的区别     139端口是一种TCP端口,该端口在通过网上邻居访问局域网中的共享文件或共享打印机时就能发挥作用.445端口也是一种TCP端口,该端口在 Windows 2 ...

  3. 【2013 ICCV】Abnormal Event Detection at 150 FPS in MATLAB

    2. method 把每一帧变成不同尺度,并且把每一层分成互不覆盖的patch.连续的5帧堆叠在一起形成时空立方体.对时空立方体计算3D梯度特征[11].这些视屏序列中的特征,根据空间位置的相关性,进 ...

  4. jQuery实现瀑布流(pc、移动通用)

    使用 jQuery 的 Masonry 插件来实现这种页面形式 1,分别下载 jQuery 与 Masonry ,然后把他们都加载到页面中使用. 加载代码: <script src=" ...

  5. Cordova插件开发

    我在网上找了很多关于Cordova插件开发的例子,都不是我想要的,我只想要,怎么调用这个生成出来的js,最终得到了最为直接又简单的方法,希望给能帮助到大家! document.addEventList ...

  6. JAVA基础-抽象类

    1. 用abstract关键字来修饰一个类时, 这个类叫做抽象类, 用abstract修饰一个方法时, 该方法叫做抽象方法 2. 含有抽象方法的类必须被声明为抽象类, 3. 抽象类必须被继承, 抽象方 ...

  7. CCS设计手段——相对定位

    1.认识相对定位 相对定位就是让元素相对自己原来的位置进行位置调整. 2.相对定位的本质特性 不脱标,老家留坑,形影分离. 3.用途 ①微调位置 ②做绝对定位的参考,子绝父相 4.相对定位的定位置 相 ...

  8. linux iptables 相关设置

    首先在使用iptables之前敲入一下两条命令 > iptables -F   #这句话的意思是清空所有的链 > iptables -X  #这句话的意思是清空所有自定义的链 以上两条的含 ...

  9. 《accelerated c++》---------第六章

    本章主要讲了算法部分.就是<algoruthm>里面的算法.

  10. Oracle存储过程中如何使用游标

    --本存储过程的功能:把test_tbl2中与test_tbl1中ID相同但salary不同的记录中的salary的值更新为test_tbl1中的salary的值--创建存储过程create or r ...