为违法网站做推广进去要几年,钓鱼转转网站在线生成,asp网站如何运行,wordpress写网站给出一个区间的集合#xff0c;请合并所有重叠的区间。 示例 1: 输入: [[1,3],[2,6],[8,10],[15,18]] #输出: [[1,6],[8,10],[15,18]] 解释: 区间 [1,3] 和 [2,6] 重叠, 将它们合并为 [1,6].
示例 2: #输入: [[1,4],[4,5]] #输出: [[1,5]] #解释: 区间 [1,4] 和 [4,5] 可被视…给出一个区间的集合请合并所有重叠的区间。 示例 1: 输入: [[1,3],[2,6],[8,10],[15,18]] #输出: [[1,6],[8,10],[15,18]] 解释: 区间 [1,3] 和 [2,6] 重叠, 将它们合并为 [1,6].
示例 2: #输入: [[1,4],[4,5]] #输出: [[1,5]] #解释: 区间 [1,4] 和 [4,5] 可被视为重叠区间。
def hebing(num_li:list): num_lisorted(num_li,keylambda x:x[0]) while len(num_li)1: for i in range(len(num_li)-1): start num_li[i] end num_li[i1] if start[1]end[0] and start[0]end[1]: num_li.insert(i,[start[0],end[1]]) num_li.remove(start) num_li.remove(end) break else: break
return num_lili1 [[1,3],[2,6],[9,100],[37,50]] res hebing(li1) print(res)