1 import datetime 2 class Solution: 3 def daysBetweenDates(self, date1: str, date2: str) -> int: 4 year1,month1,day1 = date1.split('-') 5 d1 = datetime.datetime(int(year1),int(month1),int(day1)) 6 7 year2,month2,day2 = date2.split('-') 8 d2 = datetime.datetime(int(year2),int(month2),int(day2)) 9 10 interval = abs(d2 - d1) 11 return interval.days
算法思路:使用python内置的datetime模块。