149. Max Points on a Line
来源:互联网 发布:淘宝宝贝图片下载器 编辑:程序博客网 时间:2024/06/13 08:32
import numpy as np
class Solution(object):
def maxPoints(self, points):
"""
:type points: List[Point]
:rtype: int
"""
l = len(points)
m = 0
for i in range(l):
dic = {'i': 1}
same = 0
for j in range(i+1, l):
tx, ty = points[j].x, points[j].y
if tx == points[i].x and ty == points[i].y:
same += 1
continue
if points[i].x == tx: slope = 'i'
else:slope = ((points[i].y-ty) * np.longdouble(1)) /(points[i].x-tx)
if slope not in dic: dic[slope] = 1
dic[slope] += 1
m = max(m, max(dic.values()) + same)
return m
class Solution(object):
def maxPoints(self, points):
"""
:type points: List[Point]
:rtype: int
"""
l = len(points)
m = 0
for i in range(l):
dic = {'i': 1}
same = 0
for j in range(i+1, l):
tx, ty = points[j].x, points[j].y
if tx == points[i].x and ty == points[i].y:
same += 1
continue
if points[i].x == tx: slope = 'i'
else:slope = ((points[i].y-ty) * np.longdouble(1)) /(points[i].x-tx)
if slope not in dic: dic[slope] = 1
dic[slope] += 1
m = max(m, max(dic.values()) + same)
return m
阅读全文
0 0
- LeetCode 149. Max Points on a Line
- 149.Max Points on a Line
- 149. Max Points on a Line
- [leetcode] 149. Max Points on a Line
- leetcode 149. Max Points on a Line
- Leetcode 149. Max Points on a Line
- 149. Max Points on a Line
- LeetCode 149. Max Points on a Line
- leetcode.149. Max Points on a Line
- LeetCode-149.Max Points on a Line
- 149. Max Points on a Line
- leetcode 149. Max Points on a Line
- leetCode 149. Max Points on a Line
- 149. Max Points on a Line
- [LeetCode] 149. Max Points on a Line
- 149. Max Points on a Line
- LeetCode 149. Max Points on a Line
- [LeetCode]149. Max Points on a Line
- 剑指offer——最小的K个数__(待优化)
- 【善用工具】利用Putty Tunnel从外部访问内网机器上的虚拟机
- 删除链表中的重复元素II
- 【Python学习系列五】Python网络爬虫框架Scrapy环境搭建
- BZOJ 1399 Win
- 149. Max Points on a Line
- 如何让一个DIV 居中在网页的中心
- JVM性能监控和故障处理工具
- HTTP协议
- FreeRTOS学习1--任务挂起与恢复
- CSUOJ nineteen thirteen One big silly dragon gives gifts out 线段树 二分 转化
- java中SocktTCP相关案例
- 磁盘调度 C语言实现
- 【LeetCode】48. Rotate Image