Last active
May 16, 2024 19:45
-
-
Save Itsindigo/ed09e878efbd124ff38bf748a16c67c0 to your computer and use it in GitHub Desktop.
1716. money in leetcode bank
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number} n | |
* @return {number} | |
*/ | |
var totalMoney = function(n) { | |
let total = 0 | |
let numWeeks = Math.floor(n / 7) | |
let remainingDays = n % 7 | |
for (let i=0; i < remainingDays; i++) { | |
total += i + (numWeeks + 1) | |
} | |
for (let weekNumber=0; weekNumber < numWeeks; weekNumber++) { | |
weekCost = 28 + (weekNumber * 7) | |
total += weekCost | |
} | |
return total | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment