forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0435.go
More file actions
35 lines (31 loc) · 684 Bytes
/
Copy path0435.go
File metadata and controls
35 lines (31 loc) · 684 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
func eraseOverlapIntervals(intervals [][]int) int {
if len(intervals) == 0 {
return 0
}
sort.Sort(IntSlice(intervals))
res, pre := 0, intervals[0]
for _, cur := range intervals[1:] {
if pre[1] > cur[0] {
res++
if pre[1] > cur[1] {
pre = cur
}
} else {
pre = cur
}
}
return res
}
type IntSlice [][]int
func (s IntSlice) Len() int {
return len(s)
}
func (s IntSlice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s IntSlice) Less(i, j int) bool {
if s[i][0] != s[j][0] {
return s[i][0] < s[j][0]
}
return s[i][1] < s[j][1]
}