forked from kamyu104/LeetCode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlargest-triangle-area.cpp
More file actions
23 lines (22 loc) · 881 Bytes
/
largest-triangle-area.cpp
File metadata and controls
23 lines (22 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Time: O(n^3)
// Space: O(1)
class Solution {
public:
double largestTriangleArea(vector<vector<int>>& points) {
double result = 0.0;
for (int i = 0; i < points.size() - 2; ++i) {
for (int j = i + 1; j < points.size() - 1; ++j) {
for (int k = j + 1; k < points.size(); ++k) {
result = max(result,
0.5 * abs(points[i][0] * points[j][1] +
points[j][0] * points[k][1] +
points[k][0] * points[i][1] -
points[j][0] * points[i][1] -
points[k][0] * points[j][1] -
points[i][0] * points[k][1]));
}
}
}
return result;
}
};