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. 连接Oracle数据库的Hibernate配置文件

    连接Oracle数据库的Hibernate配置文件连接Oracle的Hibernate配置文件有两种格式,一种是xml格式的,另一种是Java属性文件格式的.下面分别给出这两种格式配置文件的代码. 1 ...

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

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

  3. push控制器 卡顿

    代码: RecommendController *rec = [[RecommendController alloc]init]; [self.navigationController pushVie ...

  4. vc6 pbo 文件为空的解决方法

    使用Profile调试vc6应用程序的性能时,将生成pbo文件,今天在vc IDE中增加了命令行启动参数,导致profile无法生成pbo文件,进而无法生成性能报告. 解决方法: 去掉IDE中的命令行 ...

  5. 【转载】彻底弄懂css中单位px和em,rem的区别

    原文链接:http://www.cnblogs.com/leejersey/p/3662612.html 国内的设计师大都喜欢用px,而国外的网站大都喜欢用em和rem,那么三者有什么区别,又各自有什 ...

  6. PAT (Advanced Level) 1006. Sign In and Sign Out (25)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

  7. DIV+CSS 常见问题及解决办法整理

    http://blog.shaogroup.com/divcss-%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98%E5%8F%8A%E8%A7%A3%E5%86%B3%E5% ...

  8. 关于iOS性能调优

    性能调优一直都是作为高阶iOS开发者的一个入门门槛,下面我搜集了日常查阅资料中见到的各种高质量调优博文,仅供参考 UIKit性能调优实战讲解 iOS 高效添加圆角效果实战讲解

  9. LPC1788做U盘的时候对命令的响应

    首先是对于端点的数据处理 #ifndef __USBEP2_H_ #define __USBEP2_H_ #include "usb.h" #include "usbhw ...

  10. spring 自动化构建项目

    STS 3.7.0.RELEASE http://spring.io/tools/sts/legacy