-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLargestTriangleArea*
More file actions
28 lines (23 loc) · 851 Bytes
/
Copy pathLargestTriangleArea*
File metadata and controls
28 lines (23 loc) · 851 Bytes
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
/*******************************************/
You have a list of points in the plane. Return the area of the largest triangle that can be formed by any 3 of the points.
Example:
Input: points = [[0,0],[0,1],[1,0],[0,2],[2,0]]
Output: 2
Explanation:
The five points are show in the figure below. The red triangle is the largest.
/********************************************/
class Solution {
public:
double largestTriangleArea(vector<vector<int>>& points) {
int size = points.size();
double result = 0;
double area = 0;
for(int i=0;i<size;i++)
for(int j=i+1;j<size;j++)
for (int k = j + 1; k < size; k++) {
area = 0.5*abs(points[i][0] * (points[j][1] - points[k][1]) + points[j][0] * (points[k][1] - points[i][1]) + points[k][0] * (points[i][1] - points[j][1]));
result= max(result, area);
}
return result;
}
};