Leetcode 435. Non-overlapping Intervals

2021-02-04 10:49:54 浏览数 (1)

文章作者:Tyan 博客:noahsnail.com | CSDN | 简书

1. Description

2. Solution

代码语言:javascript复制
class Solution:
    def eraseOverlapIntervals(self, intervals):
        count = 0
        if len(intervals) < 2:
            return count
        intervals.sort(key=lambda interval: interval[1])
        overlap = intervals[0]
        for index in range(1, len(intervals)):
            if overlap[1] > intervals[index][0]:
                count  = 1
            else:
                overlap = intervals[index]

        return count

Reference

  1. https://leetcode.com/problems/non-overlapping-intervals/

0 人点赞