From 185ef9fcb0e59f13e9ee0ccb261693cdaddebab0 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 23 Feb 2021 21:07:19 +0800 Subject: import(solutions): Move leetcode solutions to subdir. --- works/solutions/leetcode/cpp/976.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 works/solutions/leetcode/cpp/976.cpp (limited to 'works/solutions/leetcode/cpp/976.cpp') diff --git a/works/solutions/leetcode/cpp/976.cpp b/works/solutions/leetcode/cpp/976.cpp new file mode 100644 index 0000000..e306047 --- /dev/null +++ b/works/solutions/leetcode/cpp/976.cpp @@ -0,0 +1,23 @@ +#include + +using std::vector; + +#include +#include + +class Solution +{ +public: + int largestPerimeter(vector &A) + { + std::sort(A.begin(), A.end(), std::greater{}); + 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; + } +}; -- cgit v1.2.3