Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a05d183

Browse files
1232. Check If It Is a Straight Line
1 parent 45bf1d7 commit a05d183

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

‎check-if-it-is-a-straight-line.cpp‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Runtime: 12 ms
2+
// Memory Usage: 10.3 MB
3+
class Solution {
4+
public:
5+
6+
float slope(vector<vector<int> > &coordinates, int i, int j) {
7+
return (float)(coordinates[j][1] - coordinates[i][1]) / (float)(coordinates[j][0] - coordinates[i][0]);
8+
}
9+
10+
bool checkStraightLine(vector<vector<int>>& coordinates) {
11+
float slp = slope(coordinates, 0, 1);
12+
13+
for (int i = 1; i < coordinates.size() - 1; i++) {
14+
if (slp != slope(coordinates, i, i + 1)) {
15+
return false;
16+
}
17+
}
18+
return true;
19+
20+
}
21+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /