← 返回 optiver 的题目列表Days Between (Unbounded Date Range)
类型:online_judge
Given two valid date strings, date1 and date2, return the absolute number of days between them.
Each date has format YYYY-MM-DD:
YYYY is an arbitrary positive integer and is not restricted to the range supported by typical date libraries.
The month is from 01 to 12.
All input dates are valid.
Use the Gregorian leap-year rule: a year is leap if it is divisible by 4 and not divisible by 100, unless it is also divisible by 400.
Do not rely on a date-time library with a bounded supported year range.
Input
date1
date2
Output
the absolute number of days between the two dates
Example 1
Input:
2019-06-29
2019-06-30
Output:
1
Example 2
Input:
2020-01-15
2019-12-31
Output:
15
Example 3
Input:
2000-02-28
2000-03-01
Output:
2
Example 4
Input:
1900-02-28
1900-03-01
Output:
1
Example 5
Input:
1000000000-12-31
1000000001-01-01
Output:
1
Example
Input
2019-06-29
2019-06-30
Output
1