Simply speaking, normal float/double can't identify the difference between 2147483644/2147483645 and 2147483643/2147483644, it should be the same value.

I spent more than 1 hour on that, at last I found in LeetCode default compiler, long double provides a better precision so that my code magically passed, but on my own PC the visual studio can't support long double, so the result is different.

Here is my 13ms code, similar to most of people.

long double degree(int x1, int y1, int x2, int y2)

{

if (x1 == x2) return (long double)INT_MAX;

return (long double)(y1 - y2) / (long double)(x1 - x2);

}

int maxPoints(vector<Point>& points) {

if (points.empty()) return 0;

int res = 0;

for (int i = 0; i < points.size(); ++i)

{

map<long double, int> smap;

int temp = 0;

int duplicate = 0;

for (int j = 0; j < points.size(); ++j)

{

if (i == j) continue;

if (points[i].x == points[j].x && points[i].y == points[j].y)

{

duplicate++;

continue;

}

long double val = degree(points[i].x, points[i].y, points[j].x, points[j].y);

smap[val]++;

}

for (auto mit : smap)

{

temp = max(temp, mit.second);

}

temp += duplicate;

res = max(res, temp);

}

return res + 1;

}