반응형
leetcode.com/problems/merge-intervals/
풀긴 하였으나 최선은 아닌 것 같다..
class Solution:
def merge(self, intervals: List[List[int]]) -> List[List[int]]:
intervals.sort(key = lambda x: x[0])
result = []
temp = intervals[0]
for i in range(1, len(intervals)):
if temp[1] >= intervals[i][0]:
temp[1] = max(temp[1],intervals[i][1])
else:
result.append(temp)
temp = intervals[i]
result.append(temp)
return result
댓글