diff options
author | crupest <crupest@outlook.com> | 2020-07-29 16:08:52 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-07-29 16:08:52 +0800 |
commit | a29a4c81b33c1489013e30333c60bcdae3301f30 (patch) | |
tree | 50f7396d22295df2a3114cc9c27d42e93c2576a0 | |
parent | 23c405d2a51119263f0c33780f739234e4e54889 (diff) | |
download | crupest-a29a4c81b33c1489013e30333c60bcdae3301f30.tar.gz crupest-a29a4c81b33c1489013e30333c60bcdae3301f30.tar.bz2 crupest-a29a4c81b33c1489013e30333c60bcdae3301f30.zip |
import(solutions): Add problem 976 .
-rw-r--r-- | works/solutions/cpp/976.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/works/solutions/cpp/976.cpp b/works/solutions/cpp/976.cpp new file mode 100644 index 0000000..e306047 --- /dev/null +++ b/works/solutions/cpp/976.cpp @@ -0,0 +1,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;
+ }
+};
|