2025-08-19 12:24:40 +0000 UTC
Count Days Spent Together
Categories:
Links
Code
class Solution:
def countDaysTogether(self, arriveAlice: str, leaveAlice: str, arriveBob: str, leaveBob: str) -> int:
months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
def count(date: str) -> int:
month = int(date[:2])
days = int(date[3:])
return sum(months[:month - 1]) + days
return max(0, count(min(leaveAlice, leaveBob)) - count(max(arriveAlice, arriveBob)) + 1)