package leetcode;

/**
 * https://leetcode.com/problems/check-if-it-is-a-straight-line/
 */
public class Problem1232 {
    public boolean checkStraightLine(int[][] coordinates) {
        // TODO
        return false;
    }

    public static void main(String[] args) {
        Problem1232 prob = new Problem1232();
        System.out.println(prob.checkStraightLine(new int[][]{
            {1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}
        })); // true
        System.out.println(prob.checkStraightLine(new int[][]{
            {1, 1}, {2, 2}, {3, 4}, {4, 5}, {5, 6}, {7, 7}
        })); // false
    }
}

package leetcode;

/**
 * https://leetcode.com/problems/check-if-it-is-a-straight-line/
 */
public class Problem1232 {
    public boolean checkStraightLine(int[][] coordinates) {
        for (int i = 0; i < coordinates.length - 2; i++) {
            if (!isColiner(
                coordinates[i][0], coordinates[i][1],
                coordinates[i + 1][0], coordinates[i + 1][1],
                coordinates[i + 2][0], coordinates[i + 2][1])) {
                return false;
            }
        }
        return true;
    }

    private static boolean isColiner(int x1, int y1, int x2, int y2, int x3, int y3) {
        // https://math.stackexchange.com/questions/701862/how-to-find-if-the-points-fall-in-a-straight-line-or-not
        return (y2 - y1) * (x3 - x1) == (y3 - y1) * (x2 - x1);
    }
}

Solve problem 1232