From 6cd1c84ebf6ae4ede32dfa3d03e2c5dab91fca4d Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Wed, 6 Dec 2023 22:31:26 +0100 Subject: [PATCH] =?UTF-8?q?problems(cpp):=20add=20=E2=80=9C1716.=20Calcula?= =?UTF-8?q?te=20Money=20in=20Leetcode=20Bank=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej Focko --- problems/cpp/calculate-money-in-leetcode-bank.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 problems/cpp/calculate-money-in-leetcode-bank.cpp diff --git a/problems/cpp/calculate-money-in-leetcode-bank.cpp b/problems/cpp/calculate-money-in-leetcode-bank.cpp new file mode 100644 index 0000000..b799b41 --- /dev/null +++ b/problems/cpp/calculate-money-in-leetcode-bank.cpp @@ -0,0 +1,15 @@ +class Solution { +public: + int totalMoney(int n) { + auto monday = 1; + + int total = 0; + for (; n >= 7; ++monday, n -= 7) { + total += 7 * (2 * monday + 7 - 1) / 2; + } + + total += n * (monday + monday + n - 1) / 2; + + return total; + } +};