Max points on a line# JobHunting - 待字闺中
e*s
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) {
}
到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) {
}