[Leet Code] Calculate Money in Leetcode Bank

Input: n = 4
Output: 10
Explanation: After the 4th day, the total is 1 + 2 + 3 + 4 = 10.
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.
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.
class Solution(object):
def totalMoney(self, n):
"""
:type n: int
:rtype: int
"""
counter = 1
acc = 0
value = 1
starting_value = 1
while counter != n+1:
if counter % 7==0:
acc+=value
counter+=1
starting_value+=1
value=starting_value

else:
acc+=value
value+=1
counter+=1

return acc

--

--

--

Learning, and posting my findings!

Love podcasts or audiobooks? Learn on the go with our new app.

Keeping it simple: Embedded IoT connected devices

33. Alpha Test is coming soon

Using Ghidra to read redacted PDFs

Designing a dynamic NFT with static JPEGs on IPFS

How to Deploy a Static Website using Github

Game Development in Ruby Using Gosu

Google search window with the text “learn game programming with ruby”

What a non techie should know about APIs (Part I)

Kiwicode startup story(9): Customers need to build complex apps, not simple ones.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Matthew Boyd

Matthew Boyd

Learning, and posting my findings!

More from Medium

LeetCode 3. Longest Substring Without Repeating Characters

[Leetcode] Median of Two Sorted Arrays

Redirecting standard input output to a file in python

LeetCode 1721: Swapping Nodes in a Linked List