1260. Day of the Year
My accepted Python solution to LeetCode problem 1260, Day of the Year, running in 11ms.
- Difficulty: Easy
- Python
- Runtime 11ms
- Memory 17.3MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 11ms, memory 17.3MB, accepted 2025-12-31.
class Solution:
def dayOfYear(self, date: str) -> int:
year, month, day = map(int, date.split('-'))
days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
days[1] = 29
return sum(days[:month-1]) + day