美文网首页
Leetcode 1716. Calculate Money i

Leetcode 1716. Calculate Money i

作者: SnailTyan | 来源:发表于2021-09-18 09:20 被阅读0次

    文章作者: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/

    相关文章

      网友评论

          本文标题:Leetcode 1716. Calculate Money i

          本文链接:https://www.haomeiwen.com/subject/npecbltx.html