From LeetCode. Collinearity. Solve the geometry problem "Check If It Is a Straight Line".
Examples
Input:[1,2,3]
Output:0
Input:[2,3,4]
Output:0
Hints
Three points are collinear when the slope between (x1,y1)→(x2,y2) equals the slope between (x1,y1)→(x3,y3). Compare cross products (y2−y1)·(x3−x1) === (x2−x1)·(y3−y1) instead of using division to avoid floating-point errors.
Fix the first two points as a reference, then loop from index 2 onward, checking each point against that reference slope.
Handle the vertical line case: if all points share the same x-coordinate, the denominator dx is 0 — the cross-product check already handles this correctly without special-casing.
Check If It Is a Straight Line
**From LeetCode.** Collinearity. Solve the geometry problem "Check If It Is a Straight Line".