这个问题可能类似于:
但是,我怎样才能获得重叠日期范围的最大数量?(最好在 C# 中)
示例:(从 - 到)
01/01/2012 - 10/01/2012
03/01/2012 - 08/01/2012
09/01/2012 - 15/01/2012
11/01/2012 - 20/01/2012
12/01/2012 - 14/01/2012
结果 = 3 个最大重叠日期范围
解决方案:@AakashM 提出的解决方案的可能实现
List<Tuple<DateTime, int>> myTupleList = new List<Tuple<DateTime, int>>();
foreach (DataRow row in objDS.Tables[0].Rows) // objDS is a DataSet with the date ranges
{
var myTupleFrom = new Tuple<DateTime, int>(DateTime.Parse(row["start_time"].ToString()), 1);
var myTupleTo = new Tuple<DateTime, int>(DateTime.Parse(row["stop_time"].ToString()), -1);
myTupleList.Add(myTupleFrom);
myTupleList.Add(myTupleTo);
}
myTupleList.Sort();
int maxConcurrentCalls = 0;
int concurrentCalls = 0;
foreach (Tuple<DateTime,int> myTuple in myTupleList)
{
if (myTuple.Item2 == 1)
{
concurrentCalls++;
if (concurrentCalls > maxConcurrentCalls)
{
maxConcurrentCalls = concurrentCalls;
}
}
else // == -1
{
concurrentCalls--;
}
}
maxConcurrentCalls
并发日期范围的最大数量在哪里。