我试图找出正确的算法来计算一组日期范围时遇到问题.
基本上我有一个无序日期范围列表(列表包含开始和结束时间的数组),我想合并这个列表,因此它不包含重叠时间.
主要是为了巩固两个日期范围:
if start1 <= end2 and start2 <= end1 //Indicates overlap
if start2 < start1 //put the smallest time in start1
start1 = start2
endif
if end2 > end1 //put the highest time in end1
end1 = end2
endif
endif
Run Code Online (Sandbox Code Playgroud)
这加入了两个日期时间.
在迭代所有值时,我遇到了绊脚石,因此结束列表只包含不重叠的值.
我的功能和递归编程有点生疏,欢迎任何帮助.
language-agnostic algorithm recursion functional-programming