Why is one of the test case so annoying?

  • 1


    I've tried calculating the slopes and count them using map, but was failing a test case all the time. No matter how many digits I set for the float it just seemed that 94911150/94911151 equals 94911151/94911152.



    It was crazy. Anyone could help me?

  • 1

    i did something like:

    double slope = 10000000000000.0 * double(points[i].y - points[j].y) / double(points[i].x - points[j].x);

    seems work, could pass the test case but might cause some overflow problem in the future...
    actually 10.0 is enough:

    double slope= 10.0*(points[i].y-points[j].y)/(points[i].x-points[j].x);

Log in to reply

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