Skip to content

Commit 845ab9b

Browse files
authored
Create 0435-non-overlapping-intervals.kt
1 parent 022d6a8 commit 845ab9b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
fun eraseOverlapIntervals(intervals: Array<IntArray>): Int {
3+
val sorted = intervals.sortedBy { it[1] }
4+
5+
var res = 0
6+
var end = -50000
7+
for ((s, e) in sorted) {
8+
if (s >= end)
9+
end = e
10+
else
11+
res++
12+
}
13+
14+
return res
15+
}
16+
}

0 commit comments

Comments
 (0)