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

Commit d40e576

Browse files
aQuaaQua
authored andcommitted
812 added
1 parent 9ada756 commit d40e576

File tree

5 files changed

+72
-1
lines changed

5 files changed

+72
-1
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# [812. Largest Triangle Area](https://leetcode.com/problems/largest-triangle-area/)
2+
3+
## 题目
4+
5+
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.
6+
7+
```text
8+
Example:
9+
Input: points = [[0,0],[0,1],[1,0],[0,2],[2,0]]
10+
Output: 2
11+
Explanation:
12+
The five points are show in the figure below. The red triangle is the largest.
13+
```
14+
15+
![pic](pic.png)
16+
17+
Notes:
18+
19+
1. 3 <= points.length <= 50.
20+
1. No points will be duplicated.
21+
1. -50 <= points[i][j] <= 50.
22+
1. Answers within 10^-6 of the true value will be accepted as correct.
23+
24+
## 解题思路
25+
26+
见程序注释
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package problem0812
2+
3+
func largestTriangleArea(points [][]int) float64 {
4+
5+
return 0
6+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package problem0812
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
// tcs is testcase slice
11+
var tcs = []struct {
12+
points [][]int
13+
ans float64
14+
}{
15+
16+
{
17+
[][]int{{0, 0}, {0, 1}, {1, 0}, {0, 2}, {2, 0}},
18+
2,
19+
},
20+
21+
// 可以有多个 testcase
22+
}
23+
24+
func Test_largestTriangleArea(t *testing.T) {
25+
ast := assert.New(t)
26+
27+
for _, tc := range tcs {
28+
fmt.Printf("~~%v~~\n", tc)
29+
ast.Equal(tc.ans, largestTriangleArea(tc.points), "输入:%v", tc)
30+
}
31+
}
32+
33+
func Benchmark_largestTriangleArea(b *testing.B) {
34+
for i := 0; i < b.N; i++ {
35+
for _, tc := range tcs {
36+
largestTriangleArea(tc.points)
37+
}
38+
}
39+
}
7.31 KB
Loading

leetcode.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Username": "aQuaYi",
33
"Ranking": 1351,
4-
"Updated": "2018-04-20T16:18:33.801050673+08:00",
4+
"Updated": "2018-04-20T16:53:01.137780299+08:00",
55
"Record": {
66
"Easy": {
77
"Solved": 165,

0 commit comments

Comments
 (0)