#1716

Calculate Money in Leetcode Bank

newbie · 145 · lc easy +13 · verified · 82.4% accepted · 1,835 likes · top 94%

Description

Hercy deposits money every day. On the first day (Monday) he puts in $1. Each subsequent day in the week he deposits $1 more than the previous day. Each new Monday starts $1 higher than the Monday before.

Given n, return the total saved at the end of day n.

Example 1:

Input: n = 4
Output: 10
Explanation: After the 4th day, the total is 1 + 2 + 3 + 4 = 10.

Example 2:

Input: n = 10
Output: 37
Explanation: After the 10th day, the total is (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4) = 37. Notice that on the 2nd Monday, Hercy only puts in $2.

Example 3:

Input: n = 20
Output: 96
Explanation: After the 20th day, the total is (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4 + 5 + 6 + 7 + 8) + (3 + 4 + 5 + 6 + 7 + 8) = 96.

Code

1
2
3