Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit d05fa22

Browse files
aQuaaQua
authored andcommitted
812 finish
1 parent d40e576 commit d05fa22

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed
Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
11
package problem0812
22

33
func largestTriangleArea(points [][]int) float64 {
4-
5-
return 0
4+
maxArea := 0.0
5+
n := len(points)
6+
for i := 0; i < n; i++ {
7+
for j := i + 1; j < n; j++ {
8+
for k := j + 1; k < n; k++ {
9+
maxArea = max(maxArea, area(points[i], points[j], points[k]))
10+
}
11+
}
12+
}
13+
return maxArea
14+
}
15+
16+
func area(p1, p2, p3 []int) float64 {
17+
return abs(p1[0]*p2[1]+p2[0]*p3[1]+p3[0]*p1[1]-p1[0]*p3[1]-p2[0]*p1[1]-p3[0]*p2[1]) / 2
18+
}
19+
20+
func abs(num int) float64 {
21+
if num < 0 {
22+
num = -num
23+
}
24+
return float64(num)
25+
}
26+
27+
func max(a, b float64) float64 {
28+
if a > b {
29+
return a
30+
}
31+
return b
632
}

0 commit comments

Comments
 (0)