add new solutions
This commit is contained in:
parent
ca24d0a56a
commit
0c73608ce5
36 changed files with 791 additions and 0 deletions
24
solutions/8/q812/solution.go
Normal file
24
solutions/8/q812/solution.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package q812
|
||||
|
||||
func area2(a, b []int) float64 {
|
||||
return float64((a[1]+b[1])*(b[0]-a[0])) / 2
|
||||
}
|
||||
|
||||
func largestTriangleArea(points [][]int) float64 {
|
||||
var maxArea float64
|
||||
|
||||
for a := 0; a < len(points)-2; a++ {
|
||||
for b := a + 1; b < len(points)-1; b++ {
|
||||
for c := b + 1; c < len(points); c++ {
|
||||
area := area2(points[a], points[b]) + area2(points[b], points[c]) + area2(points[c], points[a])
|
||||
if area < 0 {
|
||||
area = -area
|
||||
}
|
||||
maxArea = max(maxArea, area)
|
||||
}
|
||||
}
|
||||
}
|
||||
return maxArea
|
||||
}
|
||||
|
||||
var _ = largestTriangleArea
|
||||
Loading…
Add table
Add a link
Reference in a new issue