mycode  不会。。。。

参考

因为每次遍历一个点,也就是i的时候,都是新建的一个lines,所以也就是考虑了k相同b不同的情况

最后gcd函数就求最大公约数,来解决斜率精度的问题

class Solution(object):
def maxPoints(self, points):
"""
:type points: List[List[int]]
:rtype: int
"""
N = len(points)
res = 0
for i in range(N):
lines = collections.defaultdict(int)
duplicates = 1
for j in range(i + 1, N):
if points[i][0] == points[j][0] and points[i][1] == points[j][1]:
duplicates += 1
continue
dx = points[i][0] - points[j][0]
dy = points[i][1] - points[j][1]
delta = self.gcd(dx, dy)
lines[(dx / delta, dy / delta)] += 1
res = max(res, (max(lines.values()) if lines else 0) + duplicates)
return res def gcd(self, x, y):
return x if y == 0 else self.gcd(y, x % y)

leetcode-hard-array-149. Max Points on a Line -NO的更多相关文章

  1. 【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 ...

  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. [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 解题报告(Python)

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

  5. 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. ...

  6. 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. ...

  7. 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. ...

  8. 149. Max Points on a Line (Array; Greedy)

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

  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 ...

  10. 149 Max Points on a Line 直线上最多的点数

    给定二维平面上有 n 个点,求最多有多少点在同一条直线上. 详见:https://leetcode.com/problems/max-points-on-a-line/description/ Jav ...

随机推荐

  1. c++实现单向链表的一些操作

    #include<iostream> #include <algorithm> #include <vector> #include <set> #in ...

  2. kubernetes之node资源紧缺时pod驱逐机制

    在系统硬件资源紧缺的情况下保证node的稳定性, 是kubelet需要解决的一个重要问题 1.驱逐策略 kubelet持续监控主机的资源使用情况, 一旦出现资源紧缺的迹象, kubelet就会主动终止 ...

  3. [shell] shell echo打印换行的方法

    echo要支持同C语言一样的\转义功能,只需要加上参数-e,如下所示: echo -e hello \n echo \n

  4. Matlab---读取 .txt文件

    Matlab读取 .txt文件 这里提供两种方法:1,load()函数.2,importdata()函数. ---------------------------------------------- ...

  5. Maven编译指定(跳过)Module

    今天在项目里新添加了一个Module, 但是在jenkins编译的时候会将这个Module也编译, 问题是这个Module根本不需要编译而且巨慢. 因此我只想编译指定模块 ModuleA以及它依赖的必 ...

  6. JavaScript 对象中this的指向问题

    this运行在哪个对象下,就指向哪个对象.

  7. BZOJ5206 [Jsoi2017]原力[根号分治]

    这是一个三元环计数的裸题,只是多了一个颜色的区分和权值的计算罢了. 有一种根号分治的做法(by gxz) 这种复杂度的证明特别显然,思路非常简单,不过带一个log,可以用unordered_map或者 ...

  8. 2018-2019 ICPC, NEERC J. Streets and Avenues in Berhattan(DP)

    题目链接:https://codeforc.es/contest/1070/problem/J 题意:给出一个长度为 k 的字符串,选出 n 个和 m 个不同位置的字符构成两个字符串,使得两个字符串相 ...

  9. vue cli 3.x 配置使用 sourceMap

    项目使用vue cli 3.x搭建,没有了配置文件,如何更方便的查找到对应的scss文件,配置项目支持sourceMap方式? 分二步走: 1.项目根目录(不是src目录,不要搞错了)添加vue.co ...

  10. Vue 项目中对路由文件进行拆分(解构的方法)

    项目需求场景: 在开发项目过程中,在项目过于庞大,路由信息非常多的情况下,如果将路由配置信息都放在一个文件里面,那么这个JS是不方便维护的, 那么,这个时候需要我们把这个庞大的路由文件,根据项目功能分 ...