Skip to content

Commit 44b4003

Browse files
authored
Create Find Polygon With the Largest Perimeter.java
1 parent e971320 commit 44b4003

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+
class Solution {
2+
public long largestPerimeter(int[] nums) {
3+
Arrays.sort(nums);
4+
int n = nums.length;
5+
long prefixSum = 0;
6+
long result = -1;
7+
for (int i = 0; i < n; i++) {
8+
if (i >= 2 && nums[i] < prefixSum) {
9+
result = nums[i] + prefixSum;
10+
}
11+
prefixSum += nums[i];
12+
}
13+
return result;
14+
}
15+
}

0 commit comments

Comments
 (0)