邮局柜台前在排队,queue[0] 正在办,后面的人要准备好。写 NextUp(queue),返回接下来的两位。queue 至少有 1 个人;后面不够两位就有几位给几位,一个都没有就是空切片。
NextUp([]string{"Ana", "Ben", "Cai", "Dee"})→['Ben', 'Cai']NextUp([]string{"Ana", "Ben"})→['Ben']func NextUp(queue []string) []stringpackage main
func NextUp(queue []string) []string {
next := queue[1:]
// 在这里写:人多于 3 个时,把 next 换成 queue[1:3]
return next
}
写好了先点「运行」试试示例,没问题再点「提交」。