From d8f3b40085619cb680c8f227c65a1f5acc393223 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 23 Feb 2021 21:07:19 +0800 Subject: Move leetcode solutions to subdir. --- leetcode/cpp/343.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 leetcode/cpp/343.cpp (limited to 'leetcode/cpp/343.cpp') diff --git a/leetcode/cpp/343.cpp b/leetcode/cpp/343.cpp new file mode 100644 index 0000000..d31f7ce --- /dev/null +++ b/leetcode/cpp/343.cpp @@ -0,0 +1,23 @@ +#include + +class Solution +{ +public: + int integerBreak(int n) + { + if (n == 2) + return 1; + if (n == 3) + return 2; + + if (n % 3 == 1) + { + return static_cast(std::pow(3, n / 3 - 1)) * 4; + } + else if (n % 3 == 2) + { + return static_cast(std::pow(3, n / 3)) * 2; + } + return static_cast(std::pow(3, n / 3)); + } +}; -- cgit v1.2.3