problems(cpp): add “1716. Calculate Money in Leetcode Bank”
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
264f5c78db
commit
6cd1c84ebf
1 changed files with 15 additions and 0 deletions
15
problems/cpp/calculate-money-in-leetcode-bank.cpp
Normal file
15
problems/cpp/calculate-money-in-leetcode-bank.cpp
Normal 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;
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue