-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculate_money_in_leetcode_bank.py
61 lines (45 loc) · 1.58 KB
/
calculate_money_in_leetcode_bank.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'''
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.
'''
#my own solution
class Solution:
def totalMoney(self, n: int) -> int:
total = 0
q = list()
for i in range(1, n+1):
for j in range(i, i+7):
if len(q) >= (n):
print('out')
print('total sum of l')
print(sum(q))
return sum(q)
else:
print(j, end=' ')
q.append(j)
print()
class Solution:
def totalMoney(self, n: int) -> int:
start = 0
total = 0
prev = start
for i in range(1,n+1):
if i%7 == 1:
start+=1
total+=start
prev = start
else:
prev+=1
total+=prev
return total
class Solution:
def totalMoney(self, n: int) -> int:
total = 0
q,remains = divmod(n,7)
q +=1
for i in range(1, q):
total += sum([i for i in range(i, i+7)])
for i in range(q, q + remains):
total += i
return total