LeetCode - Algorithms - 976. Largest Perimeter Triangle

Problem

976. Largest Perimeter Triangle

Java

1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution {    
public int largestPerimeter(int[] A) {
Arrays.sort(A);
int a, b, c;
for (int i = A.length - 1; i >= 2; i--) {
a = A[i - 2];
b = A[i - 1];
c = A[i];
if (a + b > c) {
return a + b + c;
}
}
return 0;
}
}

Submission Detail

  • 84 / 84 test cases passed.
  • Runtime: 6 ms, faster than 99.79% of Java online submissions for Largest Perimeter Triangle.
  • Memory Usage: 39.4 MB, less than 76.17% of Java online submissions for Largest Perimeter Triangle.