【LeetCode】每日一题——1154. 一年中的第几天

目录

题目: 力扣

 思路: 


题目: 力扣

 思路: 

我横竖一看:好家伙,这不就是菜鸟上的题目吗?

思路很简单

先将数据进行处理

然后判断是不是闰年(是的话,二月分数据加一)

class Solution:
    def dayOfYear(self, date: str) -> int:
        year,month,day = [int(x) for x in date.split("-")]
        amount = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
        if year %400 == 0 or (year % 100 != 0 and year % 4 == 0):
            amount[1] += 1
        ans = sum(amount[:month-1])
        return day+ans

猜你喜欢

转载自blog.csdn.net/qq_62932195/article/details/122066746