1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/统计共同度过的日子数 [count-days-spent-together].html
2022-09-19 22:42:50 +08:00

36 lines
1.9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>Alice 和 Bob 计划分别去罗马开会。</p>
<p>给你四个字符串&nbsp;<code>arriveAlice</code>&nbsp;<code>leaveAlice</code>&nbsp;<code>arriveBob</code>&nbsp;&nbsp;<code>leaveBob</code>&nbsp;。Alice 会在日期&nbsp;<code>arriveAlice</code>&nbsp;&nbsp;<code>leaveAlice</code>&nbsp;之间在城市里(<strong>日期为闭区间</strong>),而 Bob 在日期&nbsp;<code>arriveBob</code>&nbsp;&nbsp;<code>leaveBob</code>&nbsp;之间在城市里(<strong>日期为闭区间</strong>)。每个字符串都包含 5 个字符,格式为&nbsp;<code>"MM-DD"</code>&nbsp;,对应着一个日期的月和日。</p>
<p>请你返回 Alice和 Bob 同时在罗马的天数。</p>
<p>你可以假设所有日期都在 <strong>同一个</strong>&nbsp;自然年,而且 <strong>不是</strong>&nbsp;闰年。每个月份的天数分别为:<code>[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]</code>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<b>输入:</b>arriveAlice = "08-15", leaveAlice = "08-18", arriveBob = "08-16", leaveBob = "08-19"
<b>输出:</b>3
<b>解释:</b>Alice 从 8 月 15 号到 8 月 18 号在罗马。Bob 从 8 月 16 号到 8 月 19 号在罗马,他们同时在罗马的日期为 8 月 16、17 和 18 号。所以答案为 3 。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<b>输入:</b>arriveAlice = "10-01", leaveAlice = "10-31", arriveBob = "11-01", leaveBob = "12-31"
<b>输出:</b>0
<b>解释:</b>Alice 和 Bob 没有同时在罗马的日子,所以我们返回 0 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li>所有日期的格式均为&nbsp;<code>"MM-DD"</code>&nbsp;</li>
<li>Alice 和 Bob 的到达日期都 <strong>早于或等于</strong> 他们的离开日期。</li>
<li>题目测试用例所给出的日期均为 <strong>非闰年</strong> 的有效日期。</li>
</ul>