Skip to content

Commit f60c088

Browse files
authored
Create 1232. Check If It Is a Straight Line.cpp
1 parent c1b6fa5 commit f60c088

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
LeetCode
2+
1232. Check If It Is a Straight Line
3+
4+
class Solution {
5+
public:
6+
bool checkStraightLine(vector<vector<int>>& coordinates) {
7+
int x0 = coordinates[0][0];
8+
int y0 = coordinates[0][1];
9+
int x1 = coordinates[1][0];
10+
int y1 = coordinates[1][1];
11+
int dx = x1 - x0;
12+
int dy = y1 - y0;
13+
14+
for (int i = 2; i < coordinates.size(); ++i) {
15+
int x = coordinates[i][0];
16+
int y = coordinates[i][1];
17+
if ((x - x0) * dy != (y - y0) * dx)
18+
return false;
19+
}
20+
21+
return true;
22+
}
23+
};
24+

0 commit comments

Comments
 (0)