Skip to content

Commit 39bec87

Browse files
yue2388253haoel
authored andcommitted
New C++ Solution "Largest Perimeter Triangle"
1 parent 9effb5a commit 39bec87

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
int largestPerimeter(vector<int>& A) {
4+
if (A.size() < 3) return 0;
5+
sort(A.begin(), A.end(), greater<int>());
6+
for (auto it = A.begin(); it != A.end() - 2; ++it) {
7+
if (*it < *(it + 1) + *(it + 2))
8+
return *it + *(it + 1) + *(it + 2);
9+
}
10+
return 0;
11+
}
12+
};
13+

0 commit comments

Comments
 (0)