Skip to content

Commit cac2aa6

Browse files
authored
non-overlapping intervals solution
1 parent df607f9 commit cac2aa6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
func eraseOverlapIntervals(_ intervals: [[Int]]) -> Int {
3+
let intervals = intervals.sorted() { $0[1] < $1[1] } // T(n) = S(n) = O(nlogn)
4+
var ans = 0
5+
var end = -50_000
6+
for se in intervals {
7+
if se[0] < end {
8+
ans += 1
9+
continue
10+
}
11+
end = se[1]
12+
}
13+
return ans
14+
}
15+
}

0 commit comments

Comments
 (0)