力扣 56. 合并区间

排序

1
2
3
4
5
6
7
8
9
10
11
def merge(intervals):
ret = []
intervals = sorted(intervals, key=lambda x: x[0])

for inter in intervals:
if not ret or ret[-1][1] < inter[0]:
ret.append(inter)
else:
ret[-1][1] = max(ret[-1][1], inter[1])

return ret
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2022 eightyninth
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信