Skip to content

Commit

Permalink
Create 976. Largest Perimeter Triangle.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahesh-addagatla authored Dec 20, 2024
1 parent a1d13c2 commit 6040b31
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions 976. Largest Perimeter Triangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution {
public int largestPerimeter(int[] nums) {
int n=nums.length;
Arrays.sort(nums);
for(int i=n-1;i>=2;i--){
if(nums[i]<nums[i-1]+nums[i-2]){
return nums[i]+nums[i-1]+nums[i-2];
}
}
return 0;
}
}

0 comments on commit 6040b31

Please sign in to comment.