Skip to content

Instantly share code, notes, and snippets.

@ultrasounder
Created January 27, 2020 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ultrasounder/9d17d913fa93506cdcb634ce879b0508 to your computer and use it in GitHub Desktop.
Save ultrasounder/9d17d913fa93506cdcb634ce879b0508 to your computer and use it in GitHub Desktop.
MergeIntervals
class Solution:
def merge(self, intervals: List[List[int]]) -> List[List[int]]:
intervals.sort(key=lambda x: x[0])
result = []
for curr in intervals:
if result and result[-1][1] >= curr[0]:
result[-1][1] = max(result[-1][1], curr[1])
else:
result.append(curr)
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment