forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
_812.java
22 lines (20 loc) · 843 Bytes
/
_812.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package com.fishercoder.solutions;
public class _812 {
public static class Solution1 {
/**
* reference: https://www.mathopenref.com/coordtrianglearea.html
*/
public double largestTriangleArea(int[][] points) {
double largestArea = 0.0;
for (int i = 0; i < points.length - 2; i++) {
for (int j = i + 1; j < points.length - 1; j++) {
for (int k = j + 1; k < points.length; k++) {
double area = Math.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])) / 2.0;
largestArea = Math.max(largestArea, area);
}
}
}
return largestArea;
}
}
}