The codes worked well on my computer but failed to pass the test even the same input


  • 0
    D

    Hi, dears. That's a problem hits me! And it will be really appreciative if you could give me some advice.

    I wrote some codes which could work correctly on my computer but fails to pass the test.

    It's my codes below. Thank you!

    # Definition for a point
    # class Point:
    #     def __init__(self, a=0, b=0):
    #         self.x = a
    #         self.y = b
    
    
    
    class Solution:
    
        # @param points, a list of Points
        # @return an integer
        def maxPoints(self, points):
            length = len(points)
            if len( points ) <= 1:  
                return len( points ) 
            results = {}
            for j in range(0,length,1):
                vertical_line = 0
                same_point = 0
                slopes = {}
                for i in range(0,length,1):
                    if i == j:
                        pass
                    elif points[j].x == points[i].x and points[j].y == points[i].y:
                        same_point += 1
                    elif points[j].x == points[i].x:
                        vertical_line+=1
                    elif (points[j].y-points[i].y)/(points[j].x-points[i].x) in slopes:  
                        slopes[(points[j].y-points[i].y)/(points[j].x-points[i].x)] += 1
                    else:
                        slopes[(points[j].y-points[i].y)/(points[j].x-points[i].x)] = 1
                after_sort = sorted(slopes.items(), key=lambda asd:asd[1], reverse=True)
                if after_sort and after_sort[0][1] > vertical_line:
                    results[points[j]] = after_sort[0][1] + same_point + 1
                else:results[points[j]] = vertical_line + same_point + 1
            final_result = sorted(results.items(), key=lambda asd:asd[1], reverse=True) 
            return final_result[0][1]

  • 0
    S

    Could you please tell us about the case it fails on and what the EXACT error message is?


  • 0
    D

    Of course and thanks! The case and messages are:

    Submission Result: Wrong Answer
    Input: [(84,250),(0,0),(1,0),(0,-70),(0,-70),(1,-1),(21,10),(42,90),(-42,-230)]
    Output: 8
    Expected: 6

    However, my computer run an expected "6", not "8"……


Log in to reply
 

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