class Solution:
def dayOfYear(self, date: str) -> int:
months = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]
time = date.split('-')
year = int(time[0])
month = int(time[1])
day = int(time[2])
flag = 0
if year % 400 == 0 and year % 100 != 0 or year % 4 == 0:
if month>=3:
flag = 1
return months[month - 1] + day + flag
LeetCode 1154 一年中的第几天
最新推荐文章于 2025-12-12 23:14:46 发布
本文介绍了一种将特定日期转换为一年中第几天的算法实现。通过解析输入的日期字符串,该方法能够准确计算出给定日期是一年中的第几天,并正确处理闰年的情况。
1086

被折叠的 条评论
为什么被折叠?



