File tree 1 file changed +29
-0
lines changed
1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Interval (object ):
2
+ def __init__ (self , start , end ):
3
+ self .start = start
4
<
8000
code class="diff-text syntax-highlighted-line addition">+ self .end = end
5
+
6
+
7
+ class Solution :
8
+ """
9
+ Insert a new interval into a sorted non-overlapping interval list.
10
+ @param intevals: Sorted non-overlapping interval list
11
+ @param newInterval: The new interval.
12
+ @return: A new sorted non-overlapping interval list with the new interval.
13
+ """
14
+ def insert (self , intervals , newInterval ):
15
+ results , position = [], 0
16
+
17
+ for i in intervals :
18
+ start , end = i .start , i .end
19
+ if newInterval .start > end :
20
+ results .append (i )
21
+ position += 1
22
+ elif newInterval .end < start :
23
+ results .append (i )
24
+ else :
25
+ newInterval .start = min (start , newInterval .start )
26
+ newInterval .end = max (end , newInterval .end )
27
+
28
+ results .insert (position , newInterval )
29
+ return results
You can’t perform that action at this time.
0 commit comments