Skip to content

Commit

Permalink
Create 435-Non-Overlapping-Intervals.py
Browse files Browse the repository at this point in the history
  • Loading branch information
neetcode-gh authored Dec 26, 2021
1 parent 5899e10 commit abe607d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions 435-Non-Overlapping-Intervals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution:
def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:
intervals.sort()
res = 0
prevEnd = intervals[0][1]
for start, end in intervals[1:]:
if start >= prevEnd:
prevEnd = end
else:
res += 1
prevEnd = min(end, prevEnd)
return res

0 comments on commit abe607d

Please sign in to comment.