Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.

思路:

  1. //关键在于判断三点共线,两平行直线有且只有一个交点,所以有一个中间点,这个中间点与另外两个端点的连线的斜率相等

  2. //由比率的性质

代码:

/**
 * 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 ABx;
        int ABy;
        int BCx;
        int BCy;
        if (points.length<=2)return points.length;
        int max=2;
        for (int i = 0; i 

 

你可能感兴趣的:(数据结构)