Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0028da6

Browse files
Merge pull request neetcode-gh#3307 from benmak11/2971
Create 2971-find-polygon-with-the-largest-perimeter.java
2 parents 3eb0bda + 876ab69 commit 0028da6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class Solution {
2+
3+
public long largestPerimeter(int[] nums) {
4+
Arrays.sort(nums);
5+
long res = -1, amt = 0;
6+
7+
for (int i : nums) {
8+
if (amt > i)
9+
res = amt + i;
10+
amt += i;
11+
}
12+
13+
return res;
14+
}
15+
}

0 commit comments

Comments
 (0)