Skip to content

Commit a0f8e9f

Browse files
authored
Create check-if-it-is-a-straight-line.cpp
1 parent 7d6750b commit a0f8e9f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
bool checkStraightLine(vector<vector<int>>& coordinates) {
7+
const auto& i = coordinates[0], &j = coordinates[1];
8+
return all_of(coordinates.cbegin() + 2,
9+
coordinates.cend(),
10+
[&](const auto& k) {
11+
return i[0] * j[1] - j[0] * i[1] +
12+
j[0] * k[1] - k[0] * j[1] +
13+
k[0] * i[1] - i[0] * k[1] == 0;
14+
}
15+
);
16+
}
17+
};

0 commit comments

Comments
 (0)