forked from wufenggirl/LeetCode-in-Golang
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterval.go
More file actions
30 lines (26 loc) · 694 Bytes
/
Interval.go
File metadata and controls
30 lines (26 loc) · 694 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
package kit
// Interval 提供区间表示
type Interval struct {
Start int
End int
}
// Interval2Ints 把 Interval 转换成 整型切片
func Interval2Ints(i Interval) []int {
return []int{i.Start, i.End}
}
// IntervalSlice2Intss 把 []Interval 转换成 [][]int
func IntervalSlice2Intss(is []Interval) [][]int {
res := make([][]int, 0, len(is))
for i := range is {
res = append(res, Interval2Ints(is[i]))
}
return res
}
// Intss2IntervalSlice 把 [][]int 转换成 []Interval
func Intss2IntervalSlice(intss [][]int) []Interval {
res := make([]Interval, 0, len(intss))
for _, ints := range intss {
res = append(res, Interval{Start: ints[0], End: ints[1]})
}
return res
}