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 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 nth
day.
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.
Constraints:
1 <= n <= 1000
Solv
class Solution:
def totalMoney(self, n: int) -> int:
week = 1
result = 0
reset = 0
while n > 0:
while reset < 7 and n > 0:
result += week + reset
n -= 1
reset += 1
reset = 0
week += 1
return result
think
엄청 어려운 문제는 아니었으나, 다른 사람들이 푼 것에 대해서 solution을 보면은 날짜를 나눠버리는 방식으로 많이 사용하더라. week을 7로 나누고 남은 부분에 대해서 플러스마이너스를 하는 방식으로 sol이 많은 것을 보았다.