代码拉取完成,页面将自动刷新
# Time: O(n)
# Space: O(1)
class Interval(object):
def __init__(self, s=0, e=0):
self.start = s
self.end = e
def __repr__(self):
return "[{}, {}]".format(self.start, self.end)
class Solution(object):
def insert(self, intervals, newInterval):
"""
:type intervals: List[Interval]
:type newInterval: Interval
:rtype: List[Interval]
"""
result = []
i = 0
while i < len(intervals) and newInterval.start > intervals[i].end:
result += intervals[i],
i += 1
while i < len(intervals) and newInterval.end >= intervals[i].start:
newInterval = Interval(min(newInterval.start, intervals[i].start), \
max(newInterval.end, intervals[i].end))
i += 1
result += newInterval,
result += intervals[i:]
return result
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。