728x90
https://leetcode.com/problems/insert-interval/
class Solution:
def insert(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:
new = []
for i in range(len(intervals)):
if newInterval[1]<intervals[i][0]:
new.append(newInterval)
return new+intervals[i:]
elif newInterval[0]>intervals[i][1]:
new.append(intervals[i])
else:
newInterval=[min(newInterval[0],intervals[i][0]),max(intervals[i][1],newInterval[1])]
new.append(newInterval)
return new
728x90
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 621. Task Scheduler (0) | 2024.03.19 |
---|---|
[Leetcode] 452. Minimum Number of Arrows to Burst Balloons (0) | 2024.03.19 |
[Leetcode] 3083. Existence of a Substring in a String and Its Reverse (0) | 2024.03.17 |
[Leetcode] 3079. Find the Sum of Encrypted Integers (0) | 2024.03.16 |
[Leetcode] 525. Contiguous Array (0) | 2024.03.16 |