Leetcode 435. Non-overlapping Intervals

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

1. Description

Non-overlapping Intervals

2. Solution

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/

你可能感兴趣的:(Leetcode 435. Non-overlapping Intervals)