added merge overlapping subintervals
parent
6b7530c587
commit
a9e7c67c72
|
@ -0,0 +1,10 @@
|
||||||
|
arr = [[1,2],[0,1],[3,4],[4,6],[9,10]]
|
||||||
|
arr.sort(key = lambda x : x[0])
|
||||||
|
m = []
|
||||||
|
for i in range(len(arr)):
|
||||||
|
if m==[] or m[-1][1] < arr[i][0]:
|
||||||
|
v=[arr[i][0],arr[i][1]]
|
||||||
|
m.append(v)
|
||||||
|
else:
|
||||||
|
m[-1][1] = max(m[-1][1],arr[i][1])
|
||||||
|
print(*m)
|
Loading…
Reference in New Issue