Skip to content

Commit 8b9bad6

Browse files
committed
solve problem
1 parent 1422ade commit 8b9bad6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
// Time O(n log n)
3+
// Space O(n)
4+
func eraseOverlapIntervals(_ intervals: [[Int]]) -> Int {
5+
if intervals.count < 2 { return 0 }
6+
7+
var answer = 0
8+
let intervals = intervals.sorted { $0[1] < $1[1] }
9+
var currentInterval = intervals[0]
10+
11+
for i in 1..<intervals.count {
12+
if currentInterval[1] <= intervals[i][0] {
13+
currentInterval = intervals[i]
14+
} else {
15+
answer += 1
16+
}
17+
}
18+
19+
return answer
20+
}
21+
}
22+

0 commit comments

Comments
 (0)