Leetcode 1260 Solution

This article provides solution to leetcode question 1260 (day-of-the-year)

https://leetcode.com/problems/day-of-the-year

Solution

class Solution: def dayOfYear(self, date: str) -> int: days_in_months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
year_in_str, month_in_str, day_in_str = date.split("-") year = int(year_in_str) month = int(month_in_str) day = int(day_in_str)
if year % 4 == 0: days_in_months[1] += 1
total_days = 0 for i in range(month - 1): total_days += days_in_months[i]
return total_days + day