-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution732.cs
35 lines (28 loc) · 900 Bytes
/
Solution732.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System.Text;
using LeetCode.DataStructures;
namespace LeetCode.Solutions;
public class Solution732
{
/// <summary>
/// 732. My Calendar III - Hard
/// <a href="https://leetcode.com/problems/my-calendar-iii">See the problem</a>
/// </summary>
public class MyCalendarThree
{
private readonly List<(int start, int end)> _bookings = [];
private readonly Dictionary<int, int> _events = [];
public int Book(int start, int end)
{
_events[start] = _events.GetValueOrDefault(start, 0) + 1;
_events[end] = _events.GetValueOrDefault(end, 0) - 1;
var active = 0;
var max = 0;
foreach (var (_, delta) in _events.OrderBy(e => e.Key))
{
active += delta;
max = Math.Max(max, active);
}
return max;
}
}
}