Max Points on a Line
来源:互联网 发布:tpo小站模考软件mac 编辑:程序博客网 时间:2024/05/20 09:46
https://leetcode.com/problems/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.
思路1:一开始想着构造ax+by+c=0的方程,额,好像也可以。。。O(n^2)的复杂度。。然后在比较a、b、c都相同的个数
思路2: 判断三个点在一个线上的方法有至少2中
- 根据其中2个创建函数,第三个点带入
- 计算斜率
方法1的效率太低,如果每两个点计算公式,在带入,时间复杂度为O(n^3),没必要
方法2可行,构建矩阵,存储每2个点的斜率,然后每次遍历每行,以map<double,int>存储斜率个数,斜率相同,必然
属于同一行
总结:思路2整体可以,但是存储可以免去,因为可以实时计算,然后放到map里面,但复杂度没变O(n^2)
0 0
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points On a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- max points on a line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- android得到已安装和未安装apk的信息
- Hadoop生态系统介绍
- SQL"已更新或者删除的行值要么不能使该行成为唯一行,要么改变了多个行(X行)“解决办法
- Mat imread 与 IplImage cvLoadImage区别
- devise的使用
- Max Points on a Line
- Kinect开发笔记之八C#实现Kinect声音的追踪
- spring 集成hibernate和jdbcTemplate
- 第五周阅读程序
- LeetCode | Binary Search Tree Iterator
- iOS学习之WebView的使用
- 查看oracle数据库的连接数以及用户
- 动态规划之0_1背包
- leetcode-88 Merge Sorted Array