leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1232.cpp (492B)


      1 class Solution {
      2   public:
      3     bool checkStraightLine(vector<vector<int>> &coordinates) {
      4         int n = coordinates.size();
      5         if (n == 2) return true;
      6         int x0 = coordinates[0][0], y0 = coordinates[0][1];
      7         int dx = coordinates[1][0] - x0, dy = coordinates[1][1] - y0;
      8 
      9         for (int i = 1; i < n; i++) {
     10             int x = coordinates[i][0], y = coordinates[i][1];
     11             if (dx * (y - y0) != dy * (x - x0)) return false;
     12         }
     13         return true;
     14     }
     15 };