Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f55979b

Browse files
added daily challenge
1 parent d3050b1 commit f55979b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎57. Insert Interval.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution:
2+
def insert(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:
3+
ans = []
4+
start, end = newInterval
5+
6+
inserted = False
7+
for inv in intervals:
8+
cstart, cend = inv
9+
10+
if cend < start or inserted:
11+
ans.append([cstart, cend])
12+
continue
13+
14+
start = min(start, cstart)
15+
if end < cstart:
16+
ans.append([start, end])
17+
ans.append([cstart, cend])
18+
inserted = True
19+
continue
20+
21+
if end <= cend:
22+
ans.append([start, cend])
23+
inserted = True
24+
25+
if not inserted:
26+
ans.append([start, end])
27+
28+
return ans

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /