Skip to content

Commit bad03d8

Browse files
committed
Create 0435-non-overlapping-intervals.swift
1 parent 7f79c9b commit bad03d8

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
func eraseOverlapIntervals(_ intervals: [[Int]]) -> Int {
3+
var intervals = intervals.sorted(by: { $0[0] < $1[0] })
4+
var res = 0
5+
var lastEnd = intervals[0][1]
6+
for i in 1..<intervals.count {
7+
let start = intervals[i][0]
8+
let end = intervals[i][1]
9+
if start >= lastEnd {
10+
lastEnd = end
11+
} else {
12+
res += 1
13+
lastEnd = min(lastEnd, end)
14+
}
15+
}
16+
return res
17+
}
18+
}

0 commit comments

Comments
 (0)