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

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

日期以字符串形式给出,格式为 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,643/37.3K
通过率
52.7%

相关标签

icon
相关企业

提示 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)
💡 讨论区规则

1. 请不要在评论区发表题解!

2. 评论区可以发表关于对翻译的建议、对题目的疑问及其延伸讨论。

3. 如果你需要整理题解思路,获得反馈从而进阶提升,可以去题解区进行。

暂无评论

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