题解 | #合并区间#
合并区间
https://www.nowcoder.com/practice/69f4e5b7ad284a478777cb2a17fb5e6a
# class Interval: # def __init__(self, a=0, b=0): # self.start = a # self.end = b # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param intervals Interval类一维数组 # @return Interval类一维数组 # class Solution: def merge(self , intervals: List[Interval]) -> List[Interval]: # write code here if len(intervals) < 2: return intervals intervals = sorted(intervals,key=lambda x:x.start) flter = [] front = intervals[0] for i in intervals[1:]: if i.start <= front.end: i.start = front.start i.end = max(i.end,front.end) else: flter.append(front) front = i flter.append(front) return flter
原始一点点的解法 文章被收录于专栏
尽量不借助面向对象的思想,自己去实习具体过程