2 回答

TA貢獻1796條經驗 獲得超7個贊
發送一片,而不是一片片,你可以很好地排序:
/**
* Definition for an Interval.
*/
type Interval struct {
Start int
End int
}
func employeeFreeTime(schedule []*Interval) []*Interval {
fmt.Println("Schedule initial #", schedule)
sort.Slice(schedule, func(i,j int) bool{
return schedule[i].Start < schedule[j].Start
})
fmt.Println(schedule)
return nil
}
func main() {
intervals := []*Interval {
{
Start: 10,
End: 100,
},
{
Start: 5,
End: 100,
},
}
employeeFreeTime(intervals)
}

TA貢獻1815條經驗 獲得超10個贊
如果您想對Interval切片切片中的所有 s 進行排序。
func employeeFreeTime(schedule [][]*Interval) []*Interval {
var tempSlice []*Interval
for _, slice := range schedule {
tempSlice = append(tempSlice, slice...)
}
sort.Slice(tempSlice, func(i, j int) bool {
return tempSlice[i].Start < tempSlice[j].Start
})
return tempSlice
}
- 2 回答
- 0 關注
- 129 瀏覽
添加回答
舉報