aboutsummaryrefslogtreecommitdiff
path: root/works/solutions/leetcode/cpp/976.cpp
blob: e306047c28d03c13d6cd73a717b012fad32f0b8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <vector>

using std::vector;

#include <algorithm>
#include <functional>

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