forked from DaleStudy/leetcode-study
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsounmind.py
More file actions
28 lines (20 loc) · 755 Bytes
/
sounmind.py
File metadata and controls
28 lines (20 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from typing import List
class Solution:
def insert(
self, intervals: List[List[int]], newInterval: List[int]
) -> List[List[int]]:
result = []
new_start, new_end = newInterval
for interval in intervals:
current_start, current_end = interval
if current_end < new_start:
result.append(interval)
else:
if current_start > new_end:
result.append([new_start, new_end])
new_start, new_end = interval
else:
new_start = min(new_start, current_start)
new_end = max(new_end, current_end)
result.append([new_start, new_end])
return result