2409. Count Days Spent Together Easy

@problem@discussion
#Math#String



1/**
2 * [2409] Count Days Spent Together
3 *
4 * Alice and Bob are traveling to Rome for separate business meetings.
5 * You are given 4 strings arriveAlice, leaveAlice, arriveBob, and leaveBob. Alice will be in the city from the dates arriveAlice to leaveAlice (inclusive), while Bob will be in the city from the dates arriveBob to leaveBob (inclusive). Each will be a 5-character string in the format "MM-DD", corresponding to the month and day of the date.
6 * Return the total number of days that Alice and Bob are in Rome together.
7 * You can assume that all dates occur in the same calendar year, which is not a leap year. Note that the number of days per month can be represented as: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31].
8 *  
9 * Example 1:
10 * 
11 * Input: arriveAlice = "08-15", leaveAlice = "08-18", arriveBob = "08-16", leaveBob = "08-19"
12 * Output: 3
13 * Explanation: Alice will be in Rome from August 15 to August 18. Bob will be in Rome from August 16 to August 19. They are both in Rome together on August 16th, 17th, and 18th, so the answer is 3.
14 * 
15 * Example 2:
16 * 
17 * Input: arriveAlice = "10-01", leaveAlice = "10-31", arriveBob = "11-01", leaveBob = "12-31"
18 * Output: 0
19 * Explanation: There is no day when Alice and Bob are in Rome together, so we return 0.
20 * 
21 *  
22 * Constraints:
23 * 
24 * 	All dates are provided in the format "MM-DD".
25 * 	Alice and Bob's arrival dates are earlier than or equal to their leaving dates.
26 * 	The given dates are valid dates of a non-leap year.
27 * 
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/count-days-spent-together/
32// discuss: https://leetcode.com/problems/count-days-spent-together/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37    pub fn count_days_together(arrive_alice: String, leave_alice: String, arrive_bob: String, leave_bob: String) -> i32 {
38        0
39    }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_2409() {
50    }
51}
52


Back
© 2025 bowen.ge All Rights Reserved.