文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
1. Description
2. Solution
**解析:**Version 1,使用两个变量monday
和others
表示周一和其它天,由于一周是7天,因此遍历时当碰到当天能整除7
时,表示是周一,当天存钱数量为monday+1
,同时更新monday
和others
值,当不能整除时,当天存钱数量为others+1
,更新others
值,每天的钱数累加到total
中即可。
- Version 1
class Solution:def totalMoney(self, n: int) -> int:total = 0monday = 0week = 7for i in range(n):if i % week == 0:current = monday + 1monday = currentothers = currentelse:current = others + 1others = currenttotal += currentreturn total
Reference
- https://leetcode.com/problems/calculate-money-in-leetcode-bank/