We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1422ade commit 8b9bad6Copy full SHA for 8b9bad6
non-overlapping-intervals/delight010.swift
@@ -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