Skip to content

Commit 4e5dba1

Browse files
iamAntimPalAntim-IWPIamShiwangi
committed
Update 435. Non-overlapping Intervals.py
Co-Authored-By: Antim-IWP <203163676+Antim-IWP@users.noreply.github.com> Co-Authored-By: Shiwangi Srivastava <174641070+IamShiwangi@users.noreply.github.com>
1 parent 9b4f1cf commit 4e5dba1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:
3+
intervals.sort(key=lambda x: x[1])
4+
ans = len(intervals)
5+
pre = -inf
6+
for l, r in intervals:
7+
if pre <= l:
8+
ans -= 1
9+
pre = r
10+
return ans

0 commit comments

Comments
 (0)