max-points-on-a-line leetcode C++
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.
C++
/**
* 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) {
unordered_map<float,int> mp;
int maxNum = 0;
for(int i = 0; i < points.size(); i++){
mp.clear();
mp[INT_MIN] = 0;
int duplicate = 1;
for(int j = 0; j < points.size(); j++)
{
if(j == i) continue;
if(points[i].x == points[j].x && points[i].y == points[j].y){
duplicate++;
continue;
}
float k = points[i].x == points[j].x ? INT_MAX : (float)(points[j].y - points[i].y)/(points[j].x - points[i].x);
mp[k]++;
}
unordered_map<float, int>::iterator it = mp.begin();
for(; it != mp.end(); it++)
if(it->second + duplicate > maxNum)
maxNum = it->second + duplicate;
}
return maxNum;
}
};
max-points-on-a-line leetcode C++的更多相关文章
- Max Points on a Line leetcode java
题目: Given n points on a 2D plane, find the maximum number of points that lie on the same straight li ...
- 【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 ...
- [LeetCode OJ] Max Points on a Line
Max Points on a Line Submission Details 27 / 27 test cases passed. Status: Accepted Runtime: 472 ms ...
- 【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 ...
- 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 on the ...
- [LintCode] 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. ...
- [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. ...
- 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 lin ...
- 【Max Points on a Line 】cpp
题目: Given n points on a 2D plane, find the maximum number of points that lie on the same straight li ...
- [LeetCode] 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. ...
随机推荐
- SpringMVC执行流程总结
SpringMVC 执行流程: 用户发送请求至前端控制器 DispatcherServlet DispatcherServlet 收到请求调用处理映射器 HandlerMapping 处理映射器根据请 ...
- 解决sofaboot项目右键入口方法没有run sofa application
选中入口方法名,右键出现run sofa application
- nginx 禁止某IP访问
首先建立下面的配置文件放在nginx的conf目录下面,命名为blocksip.conf: deny 95.105.25.181; 保存一下. 在nginx的配置文件nginx.conf中加入:inc ...
- swiper轮播高度不正常
第一次进入页面可能是网速原因,图片加载问题等吧,导致轮播图高度很大,下面出现空白, 需要加入参数 autoHeight: true, observer: true, observeParents: t ...
- 详细的vsftpd配置
环境:CentOS 5.0 操作系统一.安装:1.安装Vsftpd服务相关部件:[root@KcentOS5 ~]# yum install vsftpd*Dependencies Resolved= ...
- 如何实现Web视频聊天?
在网页里实现文字聊天是比较容易的,但若要实现视频聊天,就比较麻烦了.这里,我们将实现一个简单的网页版视频聊天Demo,可以支持所有类型的浏览器. 本Demo除了视频聊天功能外,还包含以下功能: 1.上 ...
- CF757F-Team Rocket Rises Again【最短路,DAG支配树】
正题 题目链接:https://www.luogu.com.cn/problem/CF757F 题目大意 \(n\)个点\(m\)条边的一张无向图,求删除\(s\)以外的一个点改变\(s\)到最多点的 ...
- VirtualBox VM 空间瘦身记(vmdk)
本文地址:https://www.ebpf.top/post/shrink_vbox_vmdk_size 在使用 VirtualBox( VMDK 模式)管理虚拟机的时候,我们经常会遇到一些编译安装场 ...
- 7.JVM调优-方法区,堆,栈调优详解
通常我们都知道在堆空间新生代Eden区满了,会触发minor GC, 在老年代满了会触发full GC, 触发full GC会导致Stop The World, 那你们知道还有一个区域满了一会触发Fu ...
- 《手把手教你》系列技巧篇(三十)-java+ selenium自动化测试- Actions的相关操作下篇(详解教程)
1.简介 本文主要介绍两个在测试过程中可能会用到的功能:Actions类中的拖拽操作和Actions类中的划取字段操作.例如:需要在一堆log字符中随机划取一段文字,然后右键选择摘取功能. 2.拖拽操 ...