Skip to content

Commit 035f018

Browse files
committed
Update insert-interval.py
1 parent 5a16320 commit 035f018

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Python/insert-interval.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ def insert(self, intervals, newInterval):
3131
return self.merge(intervals + [newInterval])
3232

3333
def merge(self, intervals):
34-
if len(intervals) == 0:
34+
if not intervals:
3535
return intervals
3636
intervals.sort(key = lambda x: x.start)
3737
result = [intervals[0]]
38-
for i in range(1, len(intervals)):
38+
for i in xrange(1, len(intervals)):
3939
prev, current = result[-1], intervals[i]
4040
if current.start <= prev.end:
4141
prev.end = max(prev.end, current.end)
@@ -44,4 +44,4 @@ def merge(self, intervals):
4444
return result
4545

4646
if __name__ == "__main__":
47-
print Solution().insert([Interval(1, 2), Interval(3, 5), Interval(6, 7), Interval(8, 10), Interval(12, 16)], Interval(4, 9))
47+
print Solution().insert([Interval(1, 2), Interval(3, 5), Interval(6, 7), Interval(8, 10), Interval(12, 16)], Interval(4, 9))

0 commit comments

Comments
 (0)