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)


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