You are viewing a single comment's thread. Return to all comments →
vector<int> maximumPerimeterTriangle(vector<int> sticks) { sort(sticks.begin(), sticks.end(), greater<int>()); for (int i = 0; i < sticks.size() - 2; ++i) { const int a = sticks[i + 2], b = sticks[i + 1], c = sticks[i]; if ( a + b > c && b + c > a && a + c > b) { return {a, b, c}; } } return {-1}; }
Seems like cookies are disabled on this browser, please enable them to open this website
Maximum Perimeter Triangle
You are viewing a single comment's thread. Return to all comments →