Merge Intervals LeetCode solution in Python

1
class Solution:
2
def merge(self, A: List[List[int]]) -> List[List[int]]:
3
# sort array wrt its 0'th index
4
A.sort(key=lambda x: x[0])
5
i = 0
6
while i < (len(A) - 1):
7
if A[i][1] >= A[i + 1][0]:
8
A[i][1] = max(A[i + 1][1], A[i][1])
9
A.pop(i + 1)
10
else:
11
i += 1
12
return A

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0