Advertisement
smj007

Merge Intervals

Aug 15th, 2024
633
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. class Solution:
  2.     def merge(self, intervals: List[List[int]]) -> List[List[int]]:
  3.          
  4.         intervals.sort()
  5.         result = []
  6.         result.append(intervals[0])
  7.  
  8.         for i in range(1, len(intervals)):
  9.             if intervals[i][0] <= result[-1][1]:
  10.                 result[-1][1] = max(intervals[i][1], result[-1][1])
  11.             else:
  12.                 result.append(intervals[i])
  13.  
  14.         return result
  15.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement