-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDay8.cpp
41 lines (38 loc) · 894 Bytes
/
Day8.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
Author: Aryan Yadav
Check If It Is a Straight Line
Complexity:O(N)
Algorithm: NA
Difficulty: Easy
*/
class Solution
{
public:
bool checkStraightLine(vector<vector<int>> &v)
{
if (v.size() == 2)
return true;
float slope_check;
float d = v[1][0] - v[0][0];
if (d == 0)
slope_check = 90;
else
{
slope_check = ((v[1][1] - v[0][1]) / d);
}
for (int i = 0; i < v.size() - 1; i++)
{
float slope;
float dd = v[i + 1][0] - v[i][0];
if (dd == 0)
slope = 90;
else
{
slope = ((v[i + 1][1] - v[i][1]) / dd);
}
if (slope != slope_check)
return false;
}
return true;
}
};