1 class Solution:
 2     def isLeap(self,year):
 3         if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
 4             return True
 5         return False
 6     
 7     def dayOfYear(self, date: str) -> int:
 8         daylist = [31,28,31,30,31,30,31,31,30,31,30,31]
 9         year,month,day = date.split('-')
10         extra = 0
11         if self.isLeap(int(year)):
12             daylist[1] = 29
13         m = int(month) - 1
14         d = int(day)
15         for i in range(m):
16             d += daylist[i]
17         return d

 

posted on 2019-09-10 16:13  Sempron2800+  阅读(150)  评论(0编辑  收藏  举报