From d991e6caf8c5b0eb2d0a5bd0679446b157233553 Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 29 Jul 2020 16:15:04 +0800 Subject: Add problem 343 . --- cpp/343.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 cpp/343.cpp (limited to 'cpp/343.cpp') diff --git a/cpp/343.cpp b/cpp/343.cpp new file mode 100644 index 0000000..d31f7ce --- /dev/null +++ b/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