leetcode-hard-array-149. Max Points on a Line -NO
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的更多相关文章
- 【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]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 line. ...
- 【LeetCode】149. Max Points on a Line 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典+最大公约数 日期 题目地址:https://l ...
- 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. ...
- 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. ...
- 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. ...
- 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. ...
- 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 ...
- 149 Max Points on a Line 直线上最多的点数
给定二维平面上有 n 个点,求最多有多少点在同一条直线上. 详见:https://leetcode.com/problems/max-points-on-a-line/description/ Jav ...
随机推荐
- 3.MySQL的架构介绍
MySQL简介: 高级MySQL:mysql 内核 sql优化工程师 mysql服务器的优化 各种参数常量设定 查询语句优化 主从复制 软硬件升级 容灾备份 sql编程 完整的mysql优化需要很深的 ...
- 【Day4】1.JsonPath使用案例
import json python_data = [ { 'username': 'normal', 'vip': True, }, { 'username':None, 'vip':False } ...
- 12_Redis_服务器命令
一:Redis 服务器:Redis 服务器命令主要是用于管理 redis 服务
- 在SqlServer和Oralce中创建索引
给表名A的字段A增加索引 SqlServer: if exists (select 1 from sysobjects where name='表名A' and type='u')and exists ...
- TcxComboBoxProperties下拉框填充
原文地址:https://www1.devexpress.com/Support/Center/Question/Details/CQ30369 Actually, the corresponding ...
- 【转】GO语言map类型interface{}转换踩坑小记
原文:https://www.az1314.cn/art/69 ------------------------------------------ mapA := make([string]inte ...
- vue 自定义指令的魅力
[第1103期]vue 自定义指令的魅力 点点 前端早读课 2017-11-08 前言 很多事情不能做过多的计划,因为计划赶不上变化.今日早读文章由富途@点点翻译分享. 正文从这开始- 在你初次接触一 ...
- Java 实现大文件切割并生成多个文件
话不多说,直接上代码 import java.io.*; /*** * 分割大文件 * ( * SQL 文件太大(insert),第三方工具无法一次性读取,进行分割 * 生成 一个一个文件 * ) * ...
- MFC 静态文本框
窗体上操作控件内容,需要句柄,在控件处使用鼠标右键——添加变量. DoDataExchange()函数会自动生成代码,把ID与变量绑定(即DDX_Control(pDX, IDC_TEXT, objT ...
- 查看PublicKeyToken和生成PublicKeyToken
http://hi.baidu.com/honfei/item/7777500b20d8ff8a02ce1bd2