由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Max points on a line
相关主题
Leetcode 新题max points on a line问一个面试题
除了某家之外,讨论个F的面试题吧,merge 2D intervalInterview questions: points lie on same line
Max Points on a Line 用c++map老是没法compileinterview question:找包含点数最多的线段
Caeercup150 原题:Find a line passes most points给一堆points, 找到所有给定长度的正方形
Max Points on a Line 最优解法是哪个?报个上周L家的onsite,已挂。继续为第6个onsite准备
lc里面那个max points O(n3)的算法也不慢啊CS interview question
Leetcode上面的题Max Points on a Line问 Facebook Onsite 一题
讨论一下给定平面上n点,求在同一直线上最多点问题~~大家用double /float 类型作hash key么顶风发个amazon电面面经
相关话题的讨论汇总
话题: point话题: points话题: max话题: 94911151话题: int
进入JobHunting版参与讨论
1 (共1页)
e*******s
发帖数: 1927
1
Max points on a line这道题,用算斜率的办法,把slope和在这个线上的点的数目放
到hashmap里。
但是leetcode上似乎有人加了一个test case,三个点
[0,0], [94911151, 94911150], [94911152, 94911151]
这样的话算出来的斜率用double是一样的,实际上这三个点不在一条线上所以出错了
用的是java,试了BigDecimal好像还是不行,这种情况怎么处理呀?大家指点一下。
原题如下:
Given n points on a 2D plane, find the maximum number of points that lie on
the same straight line.
/**
* Definition for a point.
* class Point {
* int x;
* int y;
* Point() { x = 0; y = 0; }
* Point(int a, int b) { x = a; y = b; }
* }
*/
public class Solution {
public int maxPoints(Point[] points) {
}
s**********g
发帖数: 14942
2
我从来不用double做这种比较。。。
我是把斜率约成最简
slope: s1 / s2
例如斜率0.4就是s1 = 2, s2 = 5
全部都是integer
没有任何confusion
当然corner case有好几个
例如斜率为0,斜率无穷之类的
m*****0
发帖数: 9
3
借楼问一下,这题follow up如果有很多个点,一台机器处理不了。怎么分到多个机器
上做比较好。哪位牛人能回答一下
H**********5
发帖数: 2012
4
刚刚刷这一题,同样问题,这个case死活不过。
Input:
[[0,0],[94911151,94911150],[94911152,94911151]]
Output:
3
Expected:
2
j*****e
发帖数: 56
5
这是因为计算double的时候精度不够造成的
实际上这个case是最近才加的
需要保留两个化简后的数做key就可以

【在 H**********5 的大作中提到】
: 刚刚刷这一题,同样问题,这个case死活不过。
: Input:
: [[0,0],[94911151,94911150],[94911152,94911151]]
: Output:
: 3
: Expected:
: 2

1 (共1页)
进入JobHunting版参与讨论
相关主题
顶风发个amazon电面面经Max Points on a Line 最优解法是哪个?
一道c++ primer的问题lc里面那个max points O(n3)的算法也不慢啊
Max Points on a Line应该怎么做的?Leetcode上面的题Max Points on a Line
发个论坛上某已经淡出隐牛的一道Google Onsite概率题讨论一下给定平面上n点,求在同一直线上最多点问题~~大家用double /float 类型作hash key么
Leetcode 新题max points on a line问一个面试题
除了某家之外,讨论个F的面试题吧,merge 2D intervalInterview questions: points lie on same line
Max Points on a Line 用c++map老是没法compileinterview question:找包含点数最多的线段
Caeercup150 原题:Find a line passes most points给一堆points, 找到所有给定长度的正方形
相关话题的讨论汇总
话题: point话题: points话题: max话题: 94911151话题: int