We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3fa02e1 commit 880f228Copy full SHA for 880f228
insert-interval/hu6r1s.py
@@ -0,0 +1,18 @@
1
+class Solution:
2
+ def insert(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:
3
+ intervals.append(newInterval)
4
+ intervals.sort()
5
+ output = [intervals[0]]
6
+ for x, y in intervals[1:]:
7
+ if output[-1][1] >= x:
8
+ output[-1][1] = max(y, output[-1][1])
9
+ else:
10
+ output.append([x, y])
11
+ return output
12
+
13
14
+"""
15
+newInterval을 집어넣은 다음 정렬을 해주면 인덱스 0에 있는 값 기준으로 정렬됨
16
+대소 비교를 해서 이전 배열의 인덱스 1이 현재 배열의 인덱스 0보다 크거나 같으면
17
+값을 변경해주고 아니라면 값을 그냥 추가한다.
18
0 commit comments