LC 1232. Check If It Is a Straight Line

Nilanjan Deb · April 6, 2020

This is my CPP solution.

class Solution {
public:
    bool checkStraightLine(vector<vector<int>>& coordinates) {
        int n = coordinates.size();
        if(n == 2)
            return true;
        vector<int> l_point = {coordinates[1][0], coordinates[1][1], coordinates[0][0], coordinates[0][1]};
        for(int i=2;i<n;i++){
            if((coordinates[i][1] - l_point[1])*(l_point[0] - l_point[2]) != (coordinates[i][0] - l_point[0])*(l_point[1] - l_point[3]))
                return false;
        }
        return true;
    }
};


Dicussion Forum