题目描述
对于给定的n个位于同一二维平面上的点,求最多能有多少个点位于同一直线上
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; }
* }
*/
import java.util.*;
public class Solution {
public int maxPoints(Point[] points) {
int len = points.length;
if(len < 2)
return len;
int max_points = 0;
for(int i = 0; i < len; i++){
int dup = 0, vlt = 0; //重合个数,垂直个数
Point a = points[i];
Map<Float,Integer> map = new HashMap<>(); //key为斜率
for(int j = 0; j < len; j++){
if(i == j) continue;
else{
Point b = points[j];
if(a.x &#