Created
May 23, 2020 15:05
-
-
Save kunal768/dadb4696f7aa28b723bfe8a8f109f046 to your computer and use it in GitHub Desktop.
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]]: | |
if not intervals : | |
return [] | |
ans = [] | |
intervals.sort(key = lambda x :x[0]) | |
for interval in intervals : | |
if not ans or interval[0] > ans[-1][1] : | |
ans.append(interval) | |
else: | |
ans[-1][1] = max(ans[-1][1],interval[1]) | |
return ans |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment