调试中...
调试中...
题目描述
题目描述
题解
题解
提交记录
提交记录
代码
代码
测试用例
测试用例
测试结果
测试结果
简单
相关标签
相关企业
提示

请你编写一个程序来计算两个日期之间隔了多少天。

日期以字符串形式给出,格式为 YYYY-MM-DD,如示例所示。

 

示例 1:

输入:date1 = "2019-06-29", date2 = "2019-06-30"
输出:1

示例 2:

输入:date1 = "2020-01-15", date2 = "2019-12-31"
输出:15

 

提示:

  • 给定的日期是 1971 年到 2100 年之间的有效日期。
通过次数
19.3K
提交次数
36.7K
通过率
52.5%

相关标签

相关企业

提示 1
Create a function f(date) that counts the number of days from 1900-01-01 to date. How can we calculate the answer ?

提示 2
The answer is just |f(date1) - f(date2)|.

提示 3
How to construct f(date) ?

提示 4
For each year from 1900 to year - 1 sum up 365 or 366 in case of leap years. Then sum up for each month the number of days, consider the case when the current year is leap, finally sum up the days.


评论 (0)

贡献者
© 2025 领扣网络(上海)有限公司
0 人在线
行 1,列 1
date1 =
"2019-06-29"
date2 =
"2019-06-30"
Source