aboutsummaryrefslogtreecommitdiff
path: root/calculate_money_bank.py
blob: 838ca4ca9c3e21835e9158efdd4a2fd3f4ebac17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 1716. Calculate Money in Leetcode Bank

"""
hercy wants to save money for his first car. he puts money in the leetcode
bank every day. he starts by putting in $1 on monday, the first day. every
day from tuesday to sunday he will put in 1 more dollar than the day before.
on every subsequent monday, he will put in 1 more than the previous monday.
given 'n', return the total amount of money he will have in the leetcode bank
at the end of the n'th day.
"""


class Solution(object):
    def totalMoney(self, n):
        """
        :type n: int
        :rtype: int
        """
        week = 0
        day = 1
        balance = 0
        for i in range(1, n + 1):
            balance += week + day
            day += 1
            if i % 7 == 0:
                week += 1
                day = 1
        return balance


if __name__ == "__main__":
    obj = Solution()
    print(obj.totalMoney(4))  # expect: 10
    print(obj.totalMoney(10))  # expect: 37
    print(obj.totalMoney(20))  # expect: 96