problems(cpp): add “1716. Calculate Money in Leetcode Bank”

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2023-12-06 22:31:26 +01:00
parent 264f5c78db
commit 6cd1c84ebf
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -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;
}
};