Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Dec 15, 2023
1 parent a09c6d0 commit 18e8fc7
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"fmt"
"sort"
)

func eraseOverlapIntervals(intervals [][]int) int {
sort.Slice(intervals, func(i, j int) bool {
return intervals[i][1] < intervals[j][1]
})
temp, cnt := intervals[0][1], 0
for i := 1; i < len(intervals); i++ {
if intervals[i][0] < temp {
cnt++
} else {
temp = intervals[i][1]
}
}
return cnt
}

func main() {
intervals := [][]int{{1, 2}, {2, 3}, {3, 4}, {1, 3}}
fmt.Println(eraseOverlapIntervals(intervals))
}

0 comments on commit 18e8fc7

Please sign in to comment.