package com.fishercoder.solutions;

/**
 * 1232. Check If It Is a Straight Line
 *
 * You are given an array coordinates, coordinates[i] = [x, y],
 * where [x, y] represents the coordinate of a point.
 * Check if these points make a straight line in the XY plane.
 *
 * Example 1:
 * Input: coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]
 * Output: true
 *
 * Example 2:
 * Input: coordinates = [[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]]
 * Output: false
 *
 * Constraints:
 * 2 <= coordinates.length <= 1000
 * coordinates[i].length == 2
 * -10^4 <= coordinates[i][0], coordinates[i][1] <= 10^4
 * coordinates contains no duplicate point.
 * */
public class _1232 {
    public static class Solution1 {
        /**
         * To check if they share the same slope, we use this formula:
         *
         * check whether (y4 - y3)/(x4- x3) equals to (y2 - y1)/(x2 - x1)
         * considering denominator could be zero, we'll change it to use multiplication instead of division,
         * thus it becomes
         * check whether (y4 - y3)*(x2 - x1) equals (x4 - x3)*(y2 - y1)
         * */
        public boolean checkStraightLine(int[][] coordinates) {
            for (int i = 2; i < coordinates.length - 1; i++) {
                if ((coordinates[1][0] - coordinates[0][0]) * (coordinates[i + 1][1] - coordinates[i][1])
                        != (coordinates[1][1] - coordinates[0][1]) * (coordinates[i + 1][0] - coordinates[i][0])) {
                    return false;
                }
            }
            return true;
        }
    }
}

@@ -33,618 +33,8 @@
 s;%0A%0A
-/**%0A * 1232. Check If It Is a Straight Line%0A *%0A * You are given an array coordinates, coordinates%5Bi%5D = %5Bx, y%5D,%0A * where %5Bx, y%5D represents the coordinate of a point.%0A * Check if these points make a straight line in the XY plane.%0A *%0A * Example 1:%0A * Input: coordinates = %5B%5B1,2%5D,%5B2,3%5D,%5B3,4%5D,%5B4,5%5D,%5B5,6%5D,%5B6,7%5D%5D%0A * Output: true%0A *%0A * Example 2:%0A * Input: coordinates = %5B%5B1,1%5D,%5B2,2%5D,%5B3,4%5D,%5B4,5%5D,%5B5,6%5D,%5B7,7%5D%5D%0A * Output: false%0A *%0A * Constraints:%0A * 2 %3C= coordinates.length %3C= 1000%0A * coordinates%5Bi%5D.length == 2%0A * -10%5E4 %3C= coordinates%5Bi%5D%5B0%5D, coordinates%5Bi%5D%5B1%5D %3C= 10%5E4%0A * coordinates contains no duplicate point.%0A * */%0A
 publ
@@ -470,18 +470,16 @@
         
- *
  */%0A    

refactor 1232