class Solution {
public:
int largestPerimeter(vector<int>& A) {
sort(A.begin(), A.end());
int _min = 0, _max = 0;
for (int i = A.size() - 1; i > 1; --i) {
int first = A[i], second = A[i - 1];
int pos_three = i - 2;
_min = abs(first - second), _max = first + second;
if (A[pos_three] <= _min && pos_three == 0)
return 0;
else if (A[pos_three] > _min)
return first + second + A[pos_three];
}
}
};
976. 三角形的最大周长
最新推荐文章于 2022-03-10 09:15:37 发布