Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit99e0525

Browse files
add 812
1 parent58f4bfa commit99e0525

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ _If you like this project, please leave me a star._ ★
488488
|819|[Most Common Word](https://leetcode.com/problems/most-common-word/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_819.java) | |Easy| HashMap
489489
|816|[Ambiguous Coordinates](https://leetcode.com/problems/ambiguous-coordinates/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_816.java) | |Medium| String
490490
|814|[Binary Tree Pruning](https://leetcode.com/problems/binary-tree-pruning/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_814.java) | |Medium| recursion, DFS
491+
|812|[Largest Triangle Area](https://leetcode.com/problems/largest-triangle-area/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_812.java) | |Easy| Array, Math, Geometry
491492
|811|[Subdomain Visit Count](https://leetcode.com/problems/subdomain-visit-count/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_811.java) | |Easy| HashMap
492493
|809|[Expressive Words](https://leetcode.com/problems/expressive-words/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_809.java)||Medium|
493494
|807|[Max Increase to Keep City Skyline](https://leetcode.com/problems/max-increase-to-keep-city-skyline/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_807.java)||Medium|
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_812 {
4+
publicstaticclassSolution1 {
5+
/**
6+
* reference: https://www.mathopenref.com/coordtrianglearea.html
7+
*/
8+
publicdoublelargestTriangleArea(int[][]points) {
9+
doublelargestArea =0.0;
10+
for (inti =0;i <points.length -2;i++) {
11+
for (intj =i +1;j <points.length -1;j++) {
12+
for (intk =j +1;k <points.length;k++) {
13+
doublearea =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;
14+
largestArea =Math.max(largestArea,area);
15+
16+
}
17+
}
18+
}
19+
returnlargestArea;
20+
}
21+
}
22+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.common.utils.CommonUtils;
4+
importcom.fishercoder.solutions._812;
5+
importorg.junit.BeforeClass;
6+
importorg.junit.Test;
7+
8+
importstaticorg.junit.Assert.assertEquals;
9+
10+
publicclass_812Test {
11+
privatestatic_812.Solution1solution1;
12+
13+
@BeforeClass
14+
publicstaticvoidsetup() {
15+
solution1 =new_812.Solution1();
16+
}
17+
18+
@Test
19+
publicvoidtest1() {
20+
assertEquals(2,solution1.largestTriangleArea(CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[0,0],[0,1],[1,0],[0,2],[2,0]")),0.0000001);
21+
}
22+
23+
@Test
24+
publicvoidtest2() {
25+
assertEquals(1799.0,solution1.largestTriangleArea(CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[-35,19],[40,19],[27,-20],[35,-3],[44,20],[22,-21],[35,33],[-19,42],[11,47],[11,37]")),0.0000001);
26+
}
27+
28+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp