擅长:python、mysql、java
<blockquote>
<p>I'm coding in python, but answers in any programming language are welcome, as I only need to understand the algorithm</p>
</blockquote>
<p>如果只需要伪代码,一种算法是:</p>
<pre><code>intersections = total_range
for timeline in timelines:
intersections = intersection(timeline,intersections)
</code></pre>
<p>对于实现交叉口,有几种不同的方法。一种方法是使用set函数,尽管必须转换为set,如果不希望将set作为输出,则必须将其转换回:<code>intersections = intersections.intersection(timeline)</code>。另一种方法是列表理解:<code>intersections = [time_point for time_point in intersections if time_point in timeline]</code></p>