[leetcode]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.

答案:

import java.util.*;

/**
 * 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) {
        int length = points.length;
        if(length<3)
            return length;
        int max = 2;
        for(int i=0; i map = new HashMap ();
            for(int j=i+1; j

你可能感兴趣的:([leetcode]max-points-on-a-line)