56
This commit is contained in:
parent
cd42299e73
commit
9a925bccbb
18
56-240602-pass/main.py
Normal file
18
56-240602-pass/main.py
Normal file
@ -0,0 +1,18 @@
|
||||
class Solution:
|
||||
def merge(self, intervals: List[List[int]]) -> List[List[int]]:
|
||||
sorted_intervals = sorted(intervals, key=lambda x:x[0])
|
||||
cur_l = [sorted_intervals[0][0], sorted_intervals[0][1]]
|
||||
rlt = []
|
||||
for ind, l in enumerate(sorted_intervals[1:]):
|
||||
|
||||
if cur_l[1] >= l[1] and cur_l[0]<=l[0]:pass
|
||||
elif cur_l[1] >= l[0]:
|
||||
cur_l[1] = l[1]
|
||||
else:
|
||||
r = cur_l.copy()
|
||||
rlt.append(r)
|
||||
cur_l[0]=l[0]
|
||||
cur_l[1]=l[1]
|
||||
# print(cur_l,rlt)
|
||||
rlt.append(cur_l)
|
||||
return rlt
|
Loading…
Reference in New Issue
Block a user