add: 220220 [golang] + backport 1.17

This commit is contained in:
Lam Haoyin 2022-02-21 01:41:13 +08:00
parent b40a7393cc
commit ec3020b2dc
No known key found for this signature in database
GPG Key ID: 8C089CB1A2B7544F
2 changed files with 26 additions and 1 deletions

25
golang/2202/220220.go Normal file
View File

@ -0,0 +1,25 @@
package main
import "sort"
func removeCoveredIntervals(xs [][]int) int {
sort.Slice(xs, func(i, j int) bool {
return (xs[i][1] - xs[i][0]) < (xs[j][1] - xs[j][0])
})
vis := make([]bool, len(xs))
var ret = len(xs)
for i, v := range xs {
for j := 0; j < i; j++ {
if !vis[j] && xs[j][0] >= v[0] && xs[j][1] <= v[1] {
vis[j] = true
ret--
}
}
}
return ret
}
func main() {
// Tested in C++ version
}

View File

@ -1,5 +1,5 @@
module golang
go 1.18
go 1.17
require github.com/emirpasic/gods v1.12.0