diff --git a/java/2971-find-polygon-with-the-largest-perimeter.java b/java/2971-find-polygon-with-the-largest-perimeter.java new file mode 100644 index 000000000..3c30a84b7 --- /dev/null +++ b/java/2971-find-polygon-with-the-largest-perimeter.java @@ -0,0 +1,15 @@ +public class Solution { + + public long largestPerimeter(int[] nums) { + Arrays.sort(nums); + long res = -1, amt = 0; + + for (int i : nums) { + if (amt > i) + res = amt + i; + amt += i; + } + + return res; + } +} \ No newline at end of file