-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path469.cpp
More file actions
21 lines (19 loc) · 706 Bytes
/
469.cpp
File metadata and controls
21 lines (19 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution {
public:
bool isConvex(vector<vector<int>>& points) {
int n = points.size();
long long current = 0;
long long previous = 0;
for (int i = 0; i < n; ++i) {
int x1 = points[(i + 1) % n][0] - points[(i) % n][0];
int x2 = points[(i + 2) % n][0] - points[(i + 1) % n][0];
int y1 = points[(i + 1) % n][1] - points[(i) % n][1];
int y2 = points[(i + 2) % n][1] - points[(i + 1) % n][1];
current = x1 * y2 - x2 * y1;
if (current == 0) continue;
if (current * previous < 0) return false;
previous = current;
}
return true;
}
};