Ai
1 Star 2 Fork 5

LilithSangreal/LeetCode-Solutions

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
convex-polygon.cpp 723 Bytes
Copy Edit Raw Blame History
kamyu authored 2016-12-20 15:20 +08:00 . Create convex-polygon.cpp
// Time: O(n)
// Space: O(1)
class Solution {
public:
bool isConvex(vector<vector<int>>& points) {
const auto det = [](const vector<vector<int>>& A) {
return A[0][0]*A[1][1] - A[0][1]*A[1][0];
};
long n = points.size(), prev = 0, curr;
for (int i = 0; i < n; ++i) {
vector<vector<int>> A;
for (int j = 1; j < 3; ++j) {
A.push_back({points[(i + j) % n][0] - points[i][0], points[(i + j) % n][1] - points[i][1]});
}
if (curr = det(A)) {
if (curr * prev < 0) {
return false;
}
prev = curr;
}
}
return true;
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

Search