26 / 27 test cases passed.Somebody help me please?


  • 0
    Z

    Others say that we should be careful with the double or float numbers, but I don't think my code contains that.

    public class Solution {
    public int maxPoints(Point[] points) {
        if(points.length <= 2)
            return points.length;
        int max = 2;
        for(int i=0;i<points.length-2;i++){
            for(int j=i+1;j<points.length-1;j++){
                int maxx = 2;
                int index = j;
                while(points[i].x == points[index].x && points[i].y == points[index].y){
                    if(index<points.length-1){
                        maxx++;
                        index++;
                    }else
                        break;
                }
                if(points[i].x == points[index].x){
                    for(int k=index+1;k<points.length;k++){
                        if(points[k].x == points[i].x){
                            maxx++;
                        }
                    }
                }else if(points[i].y == points[index].y){
                    for(int k=index+1;k<points.length;k++){
                        if(points[k].y == points[i].y){
                            maxx++;
                        }
                    }
                }else{
                    for(int k=index+1;k<points.length;k++){
                        if(points[i].x == points[k].x && points[i].y == points[k].y){
                            maxx++;
                        }else if(points[index].x == points[k].x && points[index].y == points[k].y){
                            maxx++;
                        }else if((points[i].y-points[index].y)*(points[i].x-points[k].x)-(points[i].x-points[index].x)*(points[i].y-points[k].y)==0){
                            maxx++;
                        }
                    }
                }
                if(maxx > max)
                    max = maxx;
            }
        }
        return max;
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.