美文网首页
LeetCode之Max points on a line

LeetCode之Max points on a line

作者: eeb7f8c13944 | 来源:发表于2018-11-03 01:08 被阅读0次

1. 问题描述

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

题意:给定一些在平面上的点,求在同一条直线上的点的最大数量。

2. 解题思路

对于任意两个点的组合,求出由这两个点确定直线的方程,再遍历所有的点,找出在该直线的点的数量,最后取最大值。

注意点:

  1. 斜率不存在的点;
  2. 只有一个点的情况。

代码实现

相关文章

网友评论

      本文标题:LeetCode之Max points on a line

      本文链接:https://www.haomeiwen.com/subject/vhihxqtx.html