Leetcode 1716. Calculate Money in Leetcode Bank

本文介绍了如何解决LeetCode中的一个题目——计算在LeetCode银行存钱的问题。作者提供了Version1的Python代码实现,通过两个变量monday和others分别表示周一和其它天的存款,根据日期是否能被7整除判断当天是周一还是其它日子,从而计算出总存款数。
摘要由CSDN通过智能技术生成

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

Calculate Money in Leetcode Bank

2. Solution

**解析:**Version 1,使用两个变量mondayothers表示周一和其它天,由于一周是7天,因此遍历时当碰到当天能整除7时,表示是周一,当天存钱数量为monday+1,同时更新mondayothers值,当不能整除时,当天存钱数量为others+1,更新others值,每天的钱数累加到total中即可。

  • Version 1
class Solution:
    def totalMoney(self, n: int) -> int:
        total = 0
        monday = 0
        week = 7
        for i in range(n):
            if i % week == 0:
                current = monday + 1
                monday = current
                others = current
            else:
                current = others + 1
                others = current
            total += current
        return total

Reference

  1. https://leetcode.com/problems/calculate-money-in-leetcode-bank/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值