Problem statement

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

Solution

Split string, then do not forgot about leap years.

Complexity

It is O(1) for time and space.

Code

class Solution:
    def dayOfYear(self, date):
        arr = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
        Y, M, D = date.split("-")
        if int(Y) % 4 == 0 and int(Y) % 1900 != 0: arr[1] += 1
        return sum(arr[:int(M) - 1]) + int(D)