Posted on

Description

Submission

class Solution {
public:
int largestPerimeter(vector<int>& A) {
sort(A.begin(), A.end(), greater<int>());
int n = A.size();
for(int i = 0; i + 2 < n; ++i) {
if(A[i] < A[i+1] + A[i+2]) {
return A[i] + A[i+1] + A[i+2];
}
}
return 0;
}
};
class Solution { public: int largestPerimeter(vector<int>& A) { sort(A.begin(), A.end(), greater<int>()); int n = A.size(); for(int i = 0; i + 2 < n; ++i) { if(A[i] < A[i+1] + A[i+2]) { return A[i] + A[i+1] + A[i+2]; } } return 0; } };
class Solution {
public:
    int largestPerimeter(vector<int>& A) {
        sort(A.begin(), A.end(), greater<int>());
        int n = A.size();

        for(int i = 0; i + 2 < n; ++i) {
            if(A[i] < A[i+1] + A[i+2]) {
                return A[i] + A[i+1] + A[i+2];
            }
        }

        return 0;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *