Created
January 27, 2020 21:13
-
-
Save ultrasounder/9d17d913fa93506cdcb634ce879b0508 to your computer and use it in GitHub Desktop.
MergeIntervals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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