149. Max Points on a Line

思路:这题的思路很简单,就是统计由每个函数上的点的数量,问题在于:
1.有重复点
2.对于垂直于x轴的线怎么处理
3.如果用double,那么对于斜率非常接近怎么处理
特殊用例:[0,MAX_INT-1,MAX_INT-2]
discussion里看到的大牛思路:
y0/x0 = (y2-y1)/(x2-x1) = (y3-y2)/(x3-x2) = a
b = y1-a*x1
利用辗转相除法,找到a,b

class Solution {
public:
    int getGCD(int a,int b){
        if(b == 0)return a;
        return getGCD(b,a%b);
    }
    int maxPoints(vector& points) {
        int n = points.size();
        if(n<2) return n;
        int result = 0;
        for(int i=0;i,int> lines;
            int v = 0;//垂直
            int over = 0;//重合
            int tempmax = 0;//最大
            for(int j =i+1;j

你可能感兴趣的:(149. Max Points on a Line)