力扣每日一题(三十二)

仅以此纪录每日LootCode所刷题目。

题目描述:

力扣每日一题(三十二)

示例:

力扣每日一题(三十二)

思路:

这道题可以将其分为两部分,第一部分是算出week的数量,第二部分是算出day的数量。week的数量可以使用int(n/7来求),day的数量可以使用n-week*7来求,之后分类讨论week为0和week大于0的情况。思路比较简单,代码也比较易懂,唯一不足的就是变量使用的太多了。

代码:

class Solution:
    def totalMoney(self, n: int) -> int:
        week = int(n / 7)
        day = n - 7*week
        if week > 0:
            weekcount = 0
            weekone = 28
            for i in range(week):
                weekcount += weekone
                weekone += 7
            dayone = 1 + week
            daycount = 0
            for i in range(day):
                daycount += dayone
                dayone += 1
        else:
            weekcount = 0
            daycount = 0
            for i in range(1,day+1):
                daycount += i
        return daycount + weekcount

 

上一篇:踩坑:java时间格式化yyyy与YYYY的区别


下一篇:Replication--复制Token