!!!闰年规则:4年一闰,百年不闰,四百年再闰。
1、整百年:必须是400的倍数。(1900不是,2000是)
2、非整百年:必须是4的倍数。如:2004
class Solution:
def DayOfYear(self, n):
dict_month = {1:31, 2:28, 3:31, 4:30, 5:31, 6:30, 7:31, 8:31, 9:30, 10:31, 11:30, 12:31}
year = n//10000
month = n%10000//100
day = n%100
flag, sum = 0, 0
if year%400==0 or (year%100 !=0 and year%4==0):
flag = 1
for i in range(1, month):
sum += dict_month[i]
sum += day
if month >2 and flag ==1:
sum += 1
return sum