Why my solution not work

  • 0

    I have wrote a solution.
    Which concept is about using a, b as key in hashtable, and collect all points to it's value

    I know line equation is "y = ax +b"* which a is slope and b is the value when x= 0

    But after I submit the solution, some test case will fail.

    Can someone point out my mistakes?


    class Solution(object):
        def maxPoints(self, points):
            :type points: List[Point]
            :rtype: int
            # y = ax + b
            if len(points) <= 2: return len(points)
            pool = {}
            for idx, p1 in enumerate(points[:-1]):
                for p2 in points[idx+1:]:
                    # vertical
                    if p1.x == p2.x:
                        if p1.x == 0:
                            a = ()
                            a = p1.x
                        b = ()
                        a = float((p1.y - p2.y))/(p1.x - p2.x)
                        b = p1.y - a*p1.x
                    pool[(a,b)] = pool.get((a,b), set()) | set([p1, p2])
            return max(map(len, pool.values()))

Log in to reply

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